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: improve CanBeCompositeSensitive #68007

Merged
merged 1 commit into from
Jul 27, 2021

Conversation

RaduBerinde
Copy link
Member

The current implementation of CanBeCompositeSensitive can be quadratic
in the expression size because each node builds the entire set of
outer columns for that subtree.

This change reworks the code and defines the logical property that we
were approximating by checking the outer cols directly. This also
reveals a bug in the previous version which did not detect relational
subtrees when there are no outer columns.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

Reviewed 2 of 9 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)

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.

Brilliant. :lgtm: 💯 🍰

Reviewed 9 of 9 files at r1.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @RaduBerinde)

The current implementation of CanBeCompositeSensitive can be quadratic
in the expression size because each node builds the entire set of
outer columns for that subtree.

This change reworks the code and defines the logical property that we
were approximating by checking the outer cols directly. This also
reveals a bug in the previous version which did not detect relational
subtrees when there are no outer columns.

Release note: None
@RaduBerinde
Copy link
Member Author

Had to update a test for PushFilterIntoSetOp - the composite check now disallows pushing down things with subqueries. Not sure if it's a problem; if it is, maybe the composite check can ignore self-contained (uncorrelated) subqueries.

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.

Had to update a test for PushFilterIntoSetOp - the composite check now disallows pushing down things with subqueries. Not sure if it's a problem; if it is, maybe the composite check can ignore self-contained (uncorrelated) subqueries.

The sub-queries that were being pushed down before seemed to add unnecessary work - there were multiple scans on a and now there is just one. I can't think of a case where pushing an uncorrelated sub-query into a set op would be desirable.

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @RaduBerinde)


pkg/sql/opt/norm/testdata/rules/select, line 1667 at r2 (raw file):

norm expect=PushFilterIntoSetOp
SELECT * FROM
  (SELECT k FROM b

Did you intend to remove this test? I guess it's similar to the one below?

Copy link
Member Author

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

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


pkg/sql/opt/norm/testdata/rules/select, line 1667 at r2 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

Did you intend to remove this test? I guess it's similar to the one below?

Yeah, didn't seem helpful given that we no longer push it down in this case.

@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 27, 2021

Build succeeded:

@craig craig bot merged commit 186313a into cockroachdb:master Jul 27, 2021
@RaduBerinde RaduBerinde deleted the comp-insensitive-cleanup branch July 28, 2021 20:32
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.

4 participants