release-20.2: opt: add transformation rule to convert left join to inner join #54110
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 #53976.
/cc @cockroachdb/release
Release justification: bug fixes and low-risk updates to new functionality
This commit adds an exploration rule
ConvertLeftToInnerJoin
, which convertsa left join to an inner join with the same
ON
condition, and then wraps theexpression in another left join with the original left side. In order to
avoid computing the left side of the join twice, we create a
With
expressionfor the left side, and then reference it with two
WithScans
. For example(assuming
x
is the primary key ofa
):is converted to:
Note that this transformation is not desirable in the general case, but it
is useful if there is a possibility of creating an inverted join (such as in
the above example). For this reason, we only perform this transformation if
it is possible to generate an inverted join.
This transformation allows us to index-accelerate spatial left joins, which
was not possible before.
Informs #53576
Release note (performance improvement): left outer spatial joins can now
be index-accelerated, which can lead to performance improvements in some
cases.