Repository navigation
aggregate_statistics should only optimize MIN/MAX when relation is not empty - #8914
Merged
Merged
Conversation
viirya
commented
Jan 19, 2024
| .as_any() | ||
| .downcast_ref::<expressions::Column>() | ||
| if let Precision::Exact(num_rows) = &stats.num_rows { | ||
| if *num_rows > 0 { |
Member
Author
There was a problem hiding this comment.
We could optimize MIN/MAX if the relation is empty (i.e., return NULL directly). Since it is not the issue itself, I will leave it as follow up.
3 of 9 tasks
alamb
approved these changes
Jan 19, 2024
| select count(*) from (select count(*) a, count(*) b from (select 1)); | ||
| ---- | ||
| 1 | ||
|
|
Contributor
There was a problem hiding this comment.
Can we also add another test where there is a single row that doesn't actually pass the predicate?
Like
CREATE TABLE t(col0 INTEGER) as VALUES(2);
SELECT MIN(col0) FROM empty WHERE col0=1;
SELECT MAX(col0) FROM empty WHERE col0=1;
So the table is not actually empty but the filter removes it all
Member
Author
There was a problem hiding this comment.
Good idea. Added that one.
Member
Author
|
Thank you @alamb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #8911.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?