-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74303: opt: split a disjunction of equijoin predicates into a union of joins r=msirek a=msirek Previously, when the ON clause of an inner, semi or anti join contained ORed equality predicates, the only available join method was cross join. This was inadequate because cross join is often the worst performing join method for joining large tables. To address this, this patch adds a new cost-based transformation which evaluates each disjunct in a separate join and unions or intersects the results together. Fixes #74302 Example query: ``` SELECT * FROM classRequest INNER JOIN classes ON classRequest.firstChoiceClassid = classes.classid OR classRequest.secondChoiceClassid = classes.classid; ``` Transformation result written in pseudo-SQL: ``` SELECT DISTINCT ON (classes.<rowid_or_primary_key_columns>, classRequest.<rowid_or_primary_key_columns>) dt.* FROM ( SELECT * FROM classRequest INNER JOIN classes ON classRequest.firstChoiceClassid = classes.classid UNION ALL SELECT * FROM classRequest INNER JOIN classes ON classRequest.secondChoiceClassid = classes.classid ) dt; ``` In addition, ORed ON clause selectivity estimation is enhanced to estimate the selectivity of each '=' predicate separately and combine the estimates in an iterative fashion like PostgreSQL does. This enables the optimizer to cost the rewritten plan more accurately so it will get picked. Release justification: Performance improvement for queries with ORed join predicates and improved selectivity estimation of ORed predicates Release note (performance improvement): Performance of inner, semi or anti join between two tables with ORed equijoin predicates is improved by enabling the optimizer to select a join plan in which each equijoin predicate is evaluated by a separate join, with the results of the joins unioned or intersected together. Co-authored-by: Mark Sirek <[email protected]>
- Loading branch information
Showing
14 changed files
with
6,964 additions
and
31 deletions.
There are no files selected for viewing
968 changes: 968 additions & 0 deletions
968
pkg/sql/logictest/testdata/logic_test/disjunction_in_join
Large diffs are not rendered by default.
Oops, something went wrong.
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.