Skip to content

Rewrite COUNT over non-nullable columns to COUNT(1) #25989

Description

@wudidapaopao

Is your feature request related to a problem or challenge?

COUNT(non_nullable_column) counts every row, but DataFusion still evaluates and reads the column unnecessarily.

Describe the solution you'd like

Rewrite safe, non-DISTINCT counts during logical simplification:

COUNT(non_nullable_column) -> COUNT(1)

Preserve the original output name and schema. For multi-argument COUNT, rewrite only when every argument is provably non-null.

Additional context

Split from #25849 as suggested in #25849 (comment).

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