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

Loading…
Cancel
Save