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 panic when hoisting expr with correlated subquery #32443

Merged
merged 1 commit into from
Nov 29, 2018

Conversation

andy-kimball
Copy link
Contributor

@andy-kimball andy-kimball commented Nov 17, 2018

Fixes #32270.

The panic occurs when hoisting an expression that has both a correlated
and an uncorrelated subquery. The current code panics when calling
Reconstruct on the relational input to the uncorrelated subquery. The
fix is to test for relational inputs and skip over them. They are not
correlated, and so no hoisting needs to be done within their subtree.

Release note (sql change): Fix panic when expression contains both a
correlated and uncorrelated subquery.

@andy-kimball andy-kimball requested a review from a team as a code owner November 17, 2018 04:28
@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

// It is not necessary to descend into relational children, because only
// subquery scalar operators have a relational child, and they are handled
// above, either because they're not correlated, or because they've already
// been hoisted.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the commit message explains this a little better than this comment. The comment implies that we skip over both correlated and uncorrelated relational expressions, but I think here the deal is that we (still) won't encounter correlated relational expressions, and we want to skip over the uncorrelated ones, right?

Copy link
Collaborator

@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.

[nit] I think you should put the issue number in the body of the commit/PR message rather than the header so that the GitHub workflow will work correctly. If you add a line to the body of the PR message that says "Fixes #32270", the craigbot will update the issue with a reference to this PR, and close the issue when this PR merges.

Also, I think this probably deserves a release note.

Otherwise, :lgtm:, once you address Justin's comment

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Contributor Author

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

This isn't a problem in 2.1, so I don't think we use a release note in that case, do we? This bug was only introduced by my expression rewrite, so it's an intra-release bug.

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


pkg/sql/opt/norm/decorrelate.go, line 800 at r1 (raw file):

Previously, justinj (Justin Jaffray) wrote…

I think the commit message explains this a little better than this comment. The comment implies that we skip over both correlated and uncorrelated relational expressions, but I think here the deal is that we (still) won't encounter correlated relational expressions, and we want to skip over the uncorrelated ones, right?

Rewrote this.

Copy link
Collaborator

@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.

But was the bug in the first 2.2 alpha release? If so, I would think the next alpha release should still have the release note. But it's definitely less important if the bug is not in 2.1...

(Also - I saw that you updated the commit message, but I think you may also need to update the PR message for the issue to be closed automatically)

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)

@andy-kimball andy-kimball changed the title opt: Issue 32270: panic when hoisting expr with correlated subquery opt: Fix panic when hoisting expr with correlated subquery Nov 28, 2018
Fixes cockroachdb#32270.

The panic occurs when hoisting an expression that has both a correlated
and an uncorrelated subquery. The current code panics when calling
Reconstruct on the relational input to the uncorrelated subquery. The
fix is to test for relational inputs and skip over them. They are not
correlated, and so no hoisting needs to be done within their subtree.

Release note (sql change): Fix panic when expression contains both a
correlated and uncorrelated subquery.
@andy-kimball
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Nov 29, 2018
32443: opt: Fix panic when hoisting expr with correlated subquery r=andy-kimball a=andy-kimball

Fixes #32270.

The panic occurs when hoisting an expression that has both a correlated
and an uncorrelated subquery. The current code panics when calling
Reconstruct on the relational input to the uncorrelated subquery. The
fix is to test for relational inputs and skip over them. They are not
correlated, and so no hoisting needs to be done within their subtree.

Release note (sql change): Fix panic when expression contains both a
correlated and uncorrelated subquery.

Co-authored-by: Andrew Kimball <[email protected]>
@craig
Copy link
Contributor

craig bot commented Nov 29, 2018

Build succeeded

@craig craig bot merged commit f429b55 into cockroachdb:master Nov 29, 2018
@andy-kimball andy-kimball deleted the decorrelate branch November 29, 2018 04:04
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: panic in optbuilder
4 participants