Refactor variable names in remove_self_joins_one_group()

Rename inner and outer to rrel and krel, respectively, to highlight their
connection to r and k indexes.  For the same reason, rename imark and omark
to rmark and kmark.

Discussion: https://postgr.es/m/18c6bd6c-6d2a-419a-b0da-dfedef34b585%40gmail.com
Author: Andrei Lepikhov <lepihov@gmail.com>
Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com>
Backpatch-through: 18
master
Alexander Korotkov 2 weeks ago
parent f8ce9ed220
commit d713cf9b65
  1. 50
      src/backend/optimizer/plan/analyzejoins.c

@ -2141,21 +2141,21 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
while ((r = bms_next_member(relids, r)) > 0)
{
RelOptInfo *inner = root->simple_rel_array[r];
RelOptInfo *rrel = root->simple_rel_array[r];
k = r;
while ((k = bms_next_member(relids, k)) > 0)
{
Relids joinrelids = NULL;
RelOptInfo *outer = root->simple_rel_array[k];
RelOptInfo *krel = root->simple_rel_array[k];
List *restrictlist;
List *selfjoinquals;
List *otherjoinquals;
ListCell *lc;
bool jinfo_check = true;
PlanRowMark *omark = NULL;
PlanRowMark *imark = NULL;
PlanRowMark *kmark = NULL;
PlanRowMark *rmark = NULL;
List *uclauses = NIL;
/* A sanity check: the relations have the same Oid. */
@ -2195,19 +2195,19 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
if (rowMark->rti == k)
{
Assert(imark == NULL);
imark = rowMark;
Assert(rmark == NULL);
rmark = rowMark;
}
else if (rowMark->rti == r)
{
Assert(omark == NULL);
omark = rowMark;
Assert(kmark == NULL);
kmark = rowMark;
}
if (omark && imark)
if (kmark && rmark)
break;
}
if (omark && imark && omark->markType != imark->markType)
if (kmark && rmark && kmark->markType != rmark->markType)
continue;
/*
@ -2228,8 +2228,8 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
* build_joinrel_restrictlist() routine.
*/
restrictlist = generate_join_implied_equalities(root, joinrelids,
inner->relids,
outer, NULL);
rrel->relids,
krel, NULL);
if (restrictlist == NIL)
continue;
@ -2239,7 +2239,7 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
* otherjoinquals.
*/
split_selfjoin_quals(root, restrictlist, &selfjoinquals,
&otherjoinquals, inner->relid, outer->relid);
&otherjoinquals, rrel->relid, krel->relid);
Assert(list_length(restrictlist) ==
(list_length(selfjoinquals) + list_length(otherjoinquals)));
@ -2250,17 +2250,17 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
* degenerate case works only if both sides have the same clause.
* So doesn't matter which side to add.
*/
selfjoinquals = list_concat(selfjoinquals, outer->baserestrictinfo);
selfjoinquals = list_concat(selfjoinquals, krel->baserestrictinfo);
/*
* Determine if the inner table can duplicate outer rows. We must
* bypass the unique rel cache here since we're possibly using a
* subset of join quals. We can use 'force_cache' == true when all
* join quals are self-join quals. Otherwise, we could end up
* putting false negatives in the cache.
* Determine if the rrel can duplicate outer rows. We must bypass
* the unique rel cache here since we're possibly using a subset
* of join quals. We can use 'force_cache' == true when all join
* quals are self-join quals. Otherwise, we could end up putting
* false negatives in the cache.
*/
if (!innerrel_is_unique_ext(root, joinrelids, inner->relids,
outer, JOIN_INNER, selfjoinquals,
if (!innerrel_is_unique_ext(root, joinrelids, rrel->relids,
krel, JOIN_INNER, selfjoinquals,
list_length(otherjoinquals) == 0,
&uclauses))
continue;
@ -2276,14 +2276,14 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
* expressions, or we won't match the same row on each side of the
* join.
*/
if (!match_unique_clauses(root, inner, uclauses, outer->relid))
if (!match_unique_clauses(root, rrel, uclauses, krel->relid))
continue;
/*
* We can remove either relation, so remove the inner one in order
* to simplify this loop.
* Remove rrel ReloptInfo from the planner structures and the
* corresponding row mark.
*/
remove_self_join_rel(root, omark, imark, outer, inner, restrictlist);
remove_self_join_rel(root, kmark, rmark, krel, rrel, restrictlist);
result = bms_add_member(result, r);

Loading…
Cancel
Save