Skip to content
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

Merged
merged 1 commit into from
May 29, 2019

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented May 29, 2019

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

@rytaft rytaft requested review from justinj and RaduBerinde May 29, 2019 15:22
@rytaft rytaft requested a review from a team as a code owner May 29, 2019 15:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@justinj justinj left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: 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
@rytaft rytaft force-pushed the fix-zero-rows-err branch from 03a972f to 6bd3023 Compare May 29, 2019 15:32
Copy link
Collaborator Author

@rytaft rytaft left a 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: :shipit: 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.

craig bot pushed a commit that referenced this pull request May 29, 2019
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]>
@craig
Copy link
Contributor

craig bot commented May 29, 2019

Build succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: internal error: estimated distinct and/or null count must be non-zero
3 participants