aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/analyzejoins.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-04-20 16:00:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-04-20 16:00:47 -0400
commitec38dcd363cd63f2a1f3cc4c47680bb16e8331b4 (patch)
tree65807f2330ef576e647aa20b93ce1c745cce6587 /src/backend/optimizer/plan/analyzejoins.c
parentc792c7db41466ff02107e3233ec9d92d8e3df866 (diff)
downloadpostgresql-ec38dcd363cd63f2a1f3cc4c47680bb16e8331b4.tar.gz
postgresql-ec38dcd363cd63f2a1f3cc4c47680bb16e8331b4.zip
Tweak a couple of planner APIs to save recalculating join relids.
Discussion: https://postgr.es/m/f8128b11-c5bf-3539-48cd-234178b2314d@proxel.se
Diffstat (limited to 'src/backend/optimizer/plan/analyzejoins.c')
-rw-r--r--src/backend/optimizer/plan/analyzejoins.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c
index c5c43626096..0e73f9cf4c7 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -42,6 +42,7 @@ static bool rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel,
List *clause_list);
static Oid distinct_col_search(int colno, List *colnos, List *opids);
static bool is_innerrel_unique_for(PlannerInfo *root,
+ Relids joinrelids,
Relids outerrelids,
RelOptInfo *innerrel,
JoinType jointype,
@@ -565,7 +566,8 @@ reduce_unique_semijoins(PlannerInfo *root)
innerrel->joininfo);
/* Test whether the innerrel is unique for those clauses. */
- if (!innerrel_is_unique(root, sjinfo->min_lefthand, innerrel,
+ if (!innerrel_is_unique(root,
+ joinrelids, sjinfo->min_lefthand, innerrel,
JOIN_SEMI, restrictlist, true))
continue;
@@ -947,7 +949,8 @@ distinct_col_search(int colno, List *colnos, List *opids)
*
* We need an actual RelOptInfo for the innerrel, but it's sufficient to
* identify the outerrel by its Relids. This asymmetry supports use of this
- * function before joinrels have been built.
+ * function before joinrels have been built. (The caller is expected to
+ * also supply the joinrelids, just to save recalculating that.)
*
* The proof must be made based only on clauses that will be "joinquals"
* rather than "otherquals" at execution. For an inner join there's no
@@ -966,6 +969,7 @@ distinct_col_search(int colno, List *colnos, List *opids)
*/
bool
innerrel_is_unique(PlannerInfo *root,
+ Relids joinrelids,
Relids outerrelids,
RelOptInfo *innerrel,
JoinType jointype,
@@ -1014,7 +1018,7 @@ innerrel_is_unique(PlannerInfo *root,
}
/* No cached information, so try to make the proof. */
- if (is_innerrel_unique_for(root, outerrelids, innerrel,
+ if (is_innerrel_unique_for(root, joinrelids, outerrelids, innerrel,
jointype, restrictlist))
{
/*
@@ -1073,12 +1077,12 @@ innerrel_is_unique(PlannerInfo *root,
*/
static bool
is_innerrel_unique_for(PlannerInfo *root,
+ Relids joinrelids,
Relids outerrelids,
RelOptInfo *innerrel,
JoinType jointype,
List *restrictlist)
{
- Relids joinrelids = bms_union(outerrelids, innerrel->relids);
List *clause_list = NIL;
ListCell *lc;