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 internal error "estimated row count must be non-zero" #53802

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Sep 2, 2020

Release justification: low risk, high benefit changes to existing
functionality

This commit fixes a rare error that could occur when a query had
many highly selective filter predicates. This error occured when the
estimated selectivity of a Select operator was 0. Prior to this commit,
we prevented the selectivity of a single filter from ever going below
1e-10, but to get the overall selectivity we multiplied the individual
selectivities together. We only needed 32 filter conditions in which
the selectivity was 1e-10 for the overall selectivity to underflow the
floating point representation and result in selectivity 0.

This commit fixes the error by setting the selectivity to 1e-10 after
multiplying the individual selectivities together if it is less than
1e-10.

Fixes #53311

Release note (bug fix): Fixed a rare internal error that could occur
during planning of queries with many highly selective predicates.

Release justification: low risk, high benefit changes to existing
functionality

This commit fixes a rare error that could occur when a query had
many highly selective filter predicates. This error occured when the
estimated selectivity of a Select operator was 0. Prior to this commit,
we prevented the selectivity of a single filter from ever going below
1e-10, but to get the overall selectivity we multiplied the individual
selectivities together. We only needed 32 filter conditions in which
the selectivity was 1e-10 for the overall selectivity to underflow the
floating point representation and result in selectivity 0.

This commit fixes the error by setting the selectivity to 1e-10 *after*
multiplying the individual selectivities together if it is less than
1e-10.

Fixes cockroachdb#53311

Release note (bug fix): Fixed a rare internal error that could occur
during planning of queries with many highly selective predicates.
@rytaft rytaft requested a review from a team as a code owner September 2, 2020 00:07
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Do we also need to add similar logic inStatistics.ApplySelectivity? If the selectivity argument and s.Selectivity are non-zero, then s.Selectivity should be set to a non-zero value.

In that case, I'm wondering if it makes sense to create a special type for selectivities (maybe just an alias for float64), with a function on the type that multiplies two selectivities but ensures if both are non-zero that the result is non-zero. This would avoid the duplicated logic and hopefully make it harder for someone in the future to forget to add this logic to new code that multiplies selectivities together.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice find!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@rytaft
Copy link
Collaborator Author

rytaft commented Sep 2, 2020

TFTRs!

Do we also need to add similar logic inStatistics.ApplySelectivity? If the selectivity argument and s.Selectivity are non-zero, then s.Selectivity should be set to a non-zero value.

We never call ApplySelectivity more than a few times for a given Statistics object, so I'm not too worried about this case.

In that case, I'm wondering if it makes sense to create a special type for selectivities (maybe just an alias for float64), with a function on the type that multiplies two selectivities but ensures if both are non-zero that the result is non-zero. This would avoid the duplicated logic and hopefully make it harder for someone in the future to forget to add this logic to new code that multiplies selectivities together.

I think that's a great idea. But since it will create changes in a lot more places, how about I save that for another PR after the stability period is over? I also plan to backport this PR, and that change will probably make the backport more difficult. I can open an issue to track it.

@mgartner
Copy link
Collaborator

mgartner commented Sep 2, 2020

I think that's a great idea. But since it will create changes in a lot more places, how about I save that for another PR after the stability period is over? I also plan to backport this PR, and that change will probably make the backport more difficult. I can open an issue to track it.

Totally!

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

$$\       $$$$$$\ $$$$$$$$\ $$\      $$\ 
$$ |     $$  __$$\\__$$  __|$$$\    $$$ |
$$ |     $$ /  \__|  $$ |   $$$$\  $$$$ |
$$ |     $$ |$$$$\   $$ |   $$\$$\$$ $$ |
$$ |     $$ |\_$$ |  $$ |   $$ \$$$  $$ |
$$ |     $$ |  $$ |  $$ |   $$ |\$  /$$ |
$$$$$$$$\\$$$$$$  |  $$ |   $$ | \_/ $$ |
\________|\______/   \__|   \__|     \__|

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.

😄

Issue here: #53860

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@craig
Copy link
Contributor

craig bot commented Sep 2, 2020

Build succeeded:

@craig craig bot merged commit 47d532f into cockroachdb:master Sep 2, 2020
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.

opt: v20.1.4: assertion failed: estimated row count must be non-zero
4 participants