forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: add transformation rule to convert left join to inner join
Release justification: bug fixes and low-risk updates to new functionality This commit adds an exploration rule ConvertLeftToInnerJoin, which converts a left join to an inner join with the same ON condition, and then wraps the expression 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 expression for the left side, and then reference it with two WithScans. For example (assuming x is the primary key of a): SELECT a.x, b.y FROM a LEFT JOIN b ON ST_Intersects(a.geom, b.geom); is converted to: WITH a_buf AS ( SELECT * FROM a ) SELECT a_buf.x, inr.y FROM a_buf LEFT JOIN ( SELECT * FROM a_buf JOIN b ON ST_Intersects(a_buf.geom, b.geom) ) AS inr ON a_buf.x = inr.x; 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 cockroachdb#53576 Release note (performance improvement): left outer spatial joins can now be index-accelerated, which can lead to performance improvements in some cases.
- Loading branch information
Showing
8 changed files
with
805 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.