diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-01 14:53:42 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-01 14:53:42 -0400 |
commit | 92a43e4857d9682b93c9f755f453cc8fd7c66c81 (patch) | |
tree | 804a1b8aa610596b00e53453894fafd94b28039a /src/backend/optimizer/plan/planmain.c | |
parent | 2057a58d1629ebffce694e3cef7f714571a88dd7 (diff) | |
download | postgresql-92a43e4857d9682b93c9f755f453cc8fd7c66c81.tar.gz postgresql-92a43e4857d9682b93c9f755f453cc8fd7c66c81.zip |
Reduce semijoins with unique inner relations to plain inner joins.
If the inner relation can be proven unique, that is it can have no more
than one matching row for any row of the outer query, then we might as
well implement the semijoin as a plain inner join, allowing substantially
more freedom to the planner. This is a form of outer join strength
reduction, but it can't be implemented in reduce_outer_joins() because
we don't have enough info about the individual relations at that stage.
Instead do it much like remove_useless_joins(): once we've built base
relations, we can make another pass over the SpecialJoinInfo list and
get rid of any entries representing reducible semijoins.
This is essentially a followon to the inner-unique patch (commit 9c7f5229a)
and makes use of the proof machinery that that patch created. We need only
minor refactoring of innerrel_is_unique's API to support this usage.
Per performance complaint from Teodor Sigaev.
Discussion: https://postgr.es/m/f994fc98-389f-4a46-d1bc-c42e05cb43ed@sigaev.ru
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r-- | src/backend/optimizer/plan/planmain.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index ef0de3fb1a9..74de3b818f7 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -193,6 +193,12 @@ query_planner(PlannerInfo *root, List *tlist, joinlist = remove_useless_joins(root, joinlist); /* + * Also, reduce any semijoins with unique inner rels to plain inner joins. + * Likewise, this can't be done until now for lack of needed info. + */ + reduce_unique_semijoins(root); + + /* * Now distribute "placeholders" to base rels as needed. This has to be * done after join removal because removal could change whether a * placeholder is evaluable at a base rel. |