Skip to content

Optimize MIN/MAX when relation is empty #8940

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Conversation

viirya
Copy link
Member

@viirya viirya commented Jan 21, 2024

Which issue does this PR close?

Closes #.

Rationale for this change

We can optimize MIN/MAX in the cases of input relation is empty.

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) labels Jan 21, 2024
Comment on lines +3279 to +3287
query TT
EXPLAIN SELECT MIN(col0) FROM empty;
----
logical_plan
Aggregate: groupBy=[[]], aggr=[[MIN(empty.col0)]]
--TableScan: empty projection=[col0]
physical_plan
ProjectionExec: expr=[NULL as MIN(empty.col0)]
--PlaceholderRowExec
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this patch, the query plan looks like:

logical_plan
Aggregate: groupBy=[[]], aggr=[[MIN(empty.col0)]]
--TableScan: empty projection=[col0]
physical_plan
AggregateExec: mode=Single, gby=[], aggr=[MIN(empty.col0)]
--MemoryExec: partitions=1, partition_sizes=[0]

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thanks @viirya

@alamb alamb merged commit eb6d63f into apache:main Jan 25, 2024
@viirya
Copy link
Member Author

viirya commented Jan 25, 2024

Thank you @alamb

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants