-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opt: fix error due to distinct and/or null count must be non-zero #37913
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde and @rytaft)
pkg/sql/opt/memo/statistics_builder.go, line 2456 at r1 (raw file):
// Transfer the null count to the distinct count since we now know that // the column is not null. We want to make sure that either the null // count or the distinct count is non-zero.
Why does the invariant that at least one of them must be non-zero exist? Is it just a consequence of the fact that we never estimate 0 rows or is there something else?
I just looked at the issue this is fixing and see that seems to be the case, maybe worth mentioning in this comment as well?
This commit fixes an issue where both the estimated distinct and null counts could be zero. This was happening because the statistics code for Select expressions was setting the null count to 0 for columns that had null-rejecting filters. If the estimated distinct count for those columns was also zero, the result was that both counts would be zero. This commit changes the logic so that the null count is now transferred to the distinct count if necessary to ensure that at least one is non-zero. Fixes cockroachdb#37754 Release note: None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @justinj and @RaduBerinde)
pkg/sql/opt/memo/statistics_builder.go, line 2456 at r1 (raw file):
Previously, justinj (Justin Jaffray) wrote…
Why does the invariant that at least one of them must be non-zero exist? Is it just a consequence of the fact that we never estimate 0 rows or is there something else?
I just looked at the issue this is fixing and see that seems to be the case, maybe worth mentioning in this comment as well?
Done.
37913: opt: fix error due to distinct and/or null count must be non-zero r=rytaft a=rytaft This commit fixes an issue where both the estimated distinct and null counts could be zero. This was happening because the statistics code for Select expressions was setting the null count to 0 for columns that had null-rejecting filters. If the estimated distinct count for those columns was also zero, the result was that both counts would be zero. This commit changes the logic so that the null count is now transferred to the distinct count if necessary to ensure that at least one is non-zero. Fixes #37754 Release note: None Co-authored-by: Rebecca Taft <[email protected]>
Build succeeded |
This commit fixes an issue where both the estimated distinct and null
counts could be zero. This was happening because the statistics code for
Select expressions was setting the null count to 0 for columns that
had null-rejecting filters. If the estimated distinct count for those
columns was also zero, the result was that both counts would be zero.
This commit changes the logic so that the null count is now transferred
to the distinct count if necessary to ensure that at least one is non-zero.
Fixes #37754
Release note: None