-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 zero-column groups in joins colliding #34667
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's fundamental to the optimizer that any two unrelated (i.e., one is not the parent of the other) expressions in the tree have disjoint column sets. Usually, this prevents the same relational expression from occurring in the tree more than once, but in the case of a group with zero columns, this is not true. This allows the following group collision to occur: Let A be the 0-column values node with two rows `VALUES (), ()`, and B be the 0-column values node with three rows `VALUES (), (), ()`. Then consider the following query: ``` (A JOIN B) UNION (B JOIN A) ``` During build, we add A JOIN B and B JOIN A to *separate memo groups*. Then, during exploration, we apply the `CommuteJoin` rule to transform `A JOIN B` to `B JOIN A`. This attempts to get interned into the same group, but the interner finds that `B JOIN A` already exists in a different group, and panics. As a side note, a values node with no columns is not valid SQL, but it can be constructed via the `MergeProjectWithValues` rule: ``` SELECT 1 FROM (VALUES (1)) => MergeProjectWithValues SELECT 1 FROM (VALUES ()) ``` This commit fixes the problem by simply disabling these types of explorations on groups with zero columns. This isn't a perfect fix, since the subtle problem is still lurking, and people going forward need to understand its implications, but it will fix the problem for the time being. Release note (bug fix): fixed several related panics in the optimizer related to plan exploration.
andy-kimball
approved these changes
Feb 6, 2019
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @andy-kimball, @RaduBerinde, and @rytaft)
TFTR! bors r+ |
craig bot
pushed a commit
that referenced
this pull request
Feb 6, 2019
34667: opt: fix zero-column groups in joins colliding r=justinj a=justinj It's fundamental to the optimizer that any two unrelated (i.e., one is not the parent of the other) expressions in the tree have disjoint column sets. Usually, this prevents the same relational expression from occurring in the tree more than once, but in the case of a group with zero columns, this is not true. This allows the following group collision to occur: Let A be the 0-column values node with two rows `VALUES (), ()`, and B be the 0-column values node with three rows `VALUES (), (), ()`. Then consider the following query: ``` (A JOIN B) UNION (B JOIN A) ``` During build, we add A JOIN B and B JOIN A to *separate memo groups*. Then, during exploration, we apply the `CommuteJoin` rule to transform `A JOIN B` to `B JOIN A`. This attempts to get interned into the same group, but the interner finds that `B JOIN A` already exists in a different group, and panics. As a side note, a values node with no columns is not valid SQL, but it can be constructed via the `MergeProjectWithValues` rule: ``` SELECT 1 FROM (VALUES (1)) => MergeProjectWithValues SELECT 1 FROM (VALUES ()) ``` This commit fixes the problem by simply disabling these types of explorations on groups with zero columns. This isn't a perfect fix, since the subtle problem is still lurking, and people going forward need to understand its implications, but it will fix the problem for the time being. Release note (bug fix): fixed several related panics in the optimizer related to plan exploration. Co-authored-by: Justin Jaffray <justin@cockroachlabs.com>
Build succeeded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's fundamental to the optimizer that any two unrelated (i.e., one is
not the parent of the other) expressions in the tree have disjoint
column sets. Usually, this prevents the same relational expression from
occurring in the tree more than once, but in the case of a group with
zero columns, this is not true.
This allows the following group collision to occur:
Let A be the 0-column values node with two rows
VALUES (), ()
,and B be the 0-column values node with three rows
VALUES (), (), ()
.Then consider the following query:
During build, we add A JOIN B and B JOIN A to separate memo groups.
Then, during exploration, we apply the
CommuteJoin
rule to transformA JOIN B
toB JOIN A
. This attempts to get interned into the samegroup, but the interner finds that
B JOIN A
already exists in adifferent group, and panics.
As a side note, a values node with no columns is not valid SQL, but it
can be constructed via the
MergeProjectWithValues
rule:This commit fixes the problem by simply disabling these types of
explorations on groups with zero columns. This isn't a perfect fix,
since the subtle problem is still lurking, and people going forward need
to understand its implications, but it will fix the problem for the time
being.
Release note (bug fix): fixed several related panics in the optimizer
related to plan exploration.