release-23.1.0: opt: hoist uncorrelated equality subqueries #101751
Closed
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.
Backport 1/1 commits from #100881.
/cc @cockroachdb/release
opt: hoist uncorrelated equality subqueries
Subqueries that are in equality expressions with a variable are now
hoisted. When these expressions exist in a filter, hoisting the subquery
can allow the main query to plan a lookup join, rather than an
inefficient full-table scan.
For example, consider the table and query:
Prior to this commit, the query plan for this query required a full
table scan:
By hoisting the subquery, the full table scan is replaced with a lookup
join:
This hoisting is disabled by default, but can be enabled by setting the
optimizer_hoist_uncorrelated_equality_subqueries
session setting totrue
.Fixes #83392
Informs #51820
Informs #93829
Informs #100855
Release note (performance improvement): Queries that have subqueries in
equality expressions are now more efficiently planned by the optimizer when
optimizer_hoist_uncorrelated_equality_subqueries
is set totrue
.Release justification: We're backporting this to 22.2, so we'll need it
to work in 23.1.0 as well.