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 incorrect number of columns after EliminateDistinct #40468

Merged
merged 1 commit into from
Sep 4, 2019

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Sep 4, 2019

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.

@rytaft rytaft requested a review from a team as a code owner September 4, 2019 13:59
@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: 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: :shipit: 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.
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!

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: :shipit: 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.

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.

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)

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

craig bot commented Sep 4, 2019

Build succeeded

@craig craig bot merged commit 0cf4a5d into cockroachdb:master Sep 4, 2019
@rytaft rytaft deleted the four-cols branch April 2, 2020 22:15
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: expected a single column but found 4 columns
3 participants