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: add EliminateConstValueSubquery normalization rule #107133
opt: add EliminateConstValueSubquery normalization rule #107133
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.
Nice idea, I'm surprised we haven't done this before.
Reviewed 9 of 9 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @rharding6373)
pkg/sql/opt/norm/rules/subquery.opt
line 10 at r1 (raw file):
[EliminateConstValueSubquery, Normalize] (Subquery (Values $rows:*) &
I think you could move the logic into optgen like this if you want:
(Values [ (Tuple [ $constant(Const) ]) ])
dea4c2a
to
2f700fb
Compare
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! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball and @rharding6373)
pkg/sql/opt/norm/rules/subquery.opt
line 10 at r1 (raw file):
Previously, DrewKimball (Drew Kimball) wrote…
I think you could move the logic into optgen like this if you want:
(Values [ (Tuple [ $constant(Const) ]) ])
Brilliant. That's much better.
pkg/sql/logictest/testdata/logic_test/apply_join
line 470 at r2 (raw file):
(VALUES (tab_54747.col_95055)) AS tab_54752 (col_95061) WHERE (SELECT random()::INT) < tab_54752.col_95061
The new rule was eliminating a subquery, which broken this test. So I changed this to a non-constant so that the rule won't fire.
7b1ff6e
to
0f90deb
Compare
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 (and 1 stale) (waiting on @DrewKimball)
0f90deb
to
2170779
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
The EliminateConstValueSubquery normalization rule replaces a subquery with a constant value when the subquery's input is a single-rows, single-column Values expression with a constant value. This enables further optimization of the query. Fixes cockroachdb#104218 Release note (performance improvement): The optimizer now produces more efficient query plans in some cases for queries with subqueries and user-defined functions.
2170779
to
bbe36ee
Compare
TFTRs! bors r+ |
Build succeeded: |
The EliminateConstValueSubquery normalization rule replaces a subquery
with a constant value when the subquery's input is a single-rows,
single-column Values expression with a constant value. This enables
further optimization of the query.
Fixes #104218
Release note (performance improvement): The optimizer now produces more
efficient query plans in some cases for queries with subqueries and
user-defined functions.