Skip to content

Rewrite COUNT with provably non-null arguments to COUNT() #25847

Description

@wudidapaopao

Is your feature request related to a problem or challenge?

DataFusion represents row-count aggregates such as COUNT(*) as COUNT(1). During execution, the scalar 1 is expanded into a full Int64Array for every input batch, although the accumulator only needs the number of rows. Similarly, COUNT(non_nullable_column) unnecessarily keeps the column in the scan.

This issue comes from profiling in #25536 (comment).

Describe the solution you'd like

Simplify non-DISTINCT COUNT calls whose arguments are safe to elide and provably non-null (for example, non-null literals and direct non-nullable columns) to a nullary COUNT(), while preserving the original output name.

Teach aggregate execution to pass the input row count explicitly so nullary COUNT works without materializing an argument array in grouped and ungrouped aggregation.

Nullable arguments, DISTINCT, and arbitrary expressions that may error or be volatile should not be rewritten.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions