-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 incorrect number of columns after EliminateDistinct #40468
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.
Don't we have some testrace tool that validates that distinct sets of logical properties are mutually consistent somehow? I wonder if it would be possible to apply that to norm rules somehow?
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @justinj, @RaduBerinde, and @rytaft)
pkg/sql/opt/norm/rules/groupby.opt, line 21 at r1 (raw file):
# redundant and can be eliminated. # # Since a DistrinctOn operator can serve as a projection operator, we need to
nit: DistrinctOn
…inct This commit fixes an error that could occur due to the EliminateDistinct rule, which eliminates a DistinctOn operator when the grouping columns are known to form a strong key. The problem with eliminating the DistinctOn completely is that it has a secondary purpose as a Project operator, and removing it could result in an incorrect number of output columns. This commit fixes that rule so that it replaces the DistinctOn with a Project operator. Release note (bug fix): Fixed an internal planning error that could occur when a DISTINCT or GROUP BY expression was contained in a subquery.
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!
Don't we have some testrace tool that validates that distinct sets of logical properties are mutually consistent somehow? I wonder if it would be possible to apply that to norm rules somehow?
That's a good idea, although it would be tricky. As written, checkExpr
checks that the logical properties calculated from each expression in a group (produced by exploration rules) are consistent. The problem with norm rules is that they only add one expression to the group, so we'd need to find a way to selectively disable some norm rules and check that all resulting expressions produce the same logical properties. Might be worth doing as a test infrastructure project once we finish all the 19.2 issues....
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)
pkg/sql/opt/norm/rules/groupby.opt, line 21 at r1 (raw file):
Previously, justinj (Justin Jaffray) wrote…
nit:
DistrinctOn
Done.
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.
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)
40468: opt: fix error due to incorrect number of columns after EliminateDistinct r=rytaft a=rytaft This commit fixes an error that could occur due to the `EliminateDistinct` rule, which eliminates a `DistinctOn` operator when the grouping columns are known to form a strong key. The problem with eliminating the `DistinctOn` completely is that it has a secondary purpose as a `Project` operator, and removing it could result in an incorrect number of output columns. This commit fixes that rule so that it replaces the `DistinctOn` with a `Project` operator. Fixes #40295 Release note (bug fix): Fixed an internal planning error that could occur when a DISTINCT or GROUP BY expression was contained in a subquery. Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Build succeeded |
This commit fixes an error that could occur due to the
EliminateDistinct
rule, which eliminates a
DistinctOn
operator when the grouping columnsare known to form a strong key. The problem with eliminating the
DistinctOn
completely is that it has a secondary purpose as a
Project
operator, andremoving it could result in an incorrect number of output columns. This
commit fixes that rule so that it replaces the
DistinctOn
with aProject
operator.
Fixes #40295
Release note (bug fix): Fixed an internal planning error that could
occur when a DISTINCT or GROUP BY expression was contained in a subquery.