-
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.
opt: split a disjunction of equijoin predicates into a union of joins
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 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.
- Loading branch information
Showing
11 changed files
with
1,502 additions
and
18 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
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.