Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8951941

Browse files
committed
Improve RowMark handling during Self-Join Elimination
The Self-Join Elimination SJE feature messes up keeping and removing RowMark'sin remove_self_joins_one_group(). That didn't lead to user-level error,because the planned RowMark is only used to reference a rtable entry in laterexecution stages. An RTE entry for keeping and removing relations isidentical and refers to the same relation OID.To reduce confusion and prevent future issues, this commit cleans up the codeand fixes the incorrect behaviour. Furthermore, it includes sanity checks insetrefs.c on existing non-null RTE and RelOptInfo entries for each RowMark.Discussion:https://postgr.es/m/18c6bd6c-6d2a-419a-b0da-dfedef34b585%40gmail.comAuthor: Andrei Lepikhov <lepihov@gmail.com>Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com>Backpatch-through: 18
1 parent8202b0e commit8951941

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

‎src/backend/optimizer/plan/analyzejoins.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ remove_leftjoinrel_from_query(PlannerInfo *root, int relid,
631631
* remove_join_clause_from_rels will touch it.)
632632
*/
633633
root->simple_rel_array[relid]=NULL;
634+
root->simple_rte_array[relid]=NULL;
634635

635636
/* And nuke the RelOptInfo, just in case there's another access path */
636637
pfree(rel);
@@ -1979,10 +1980,12 @@ remove_self_join_rel(PlannerInfo *root, PlanRowMark *kmark, PlanRowMark *rmark,
19791980
* remove_join_clause_from_rels will touch it.)
19801981
*/
19811982
root->simple_rel_array[toRemove->relid]=NULL;
1983+
root->simple_rte_array[toRemove->relid]=NULL;
19821984

19831985
/* And nuke the RelOptInfo, just in case there's another access path. */
19841986
pfree(toRemove);
19851987

1988+
19861989
/*
19871990
* Now repeat construction of attr_needed bits coming from all other
19881991
* sources.
@@ -2194,12 +2197,12 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
21942197
{
21952198
PlanRowMark*rowMark= (PlanRowMark*)lfirst(lc);
21962199

2197-
if (rowMark->rti==k)
2200+
if (rowMark->rti==r)
21982201
{
21992202
Assert(rmark==NULL);
22002203
rmark=rowMark;
22012204
}
2202-
elseif (rowMark->rti==r)
2205+
elseif (rowMark->rti==k)
22032206
{
22042207
Assert(kmark==NULL);
22052208
kmark=rowMark;
@@ -2254,7 +2257,7 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
22542257
selfjoinquals=list_concat(selfjoinquals,krel->baserestrictinfo);
22552258

22562259
/*
2257-
* Determine if the rrel can duplicate outer rows.We must bypass
2260+
* Determine if the rrel can duplicate outer rows. We must bypass
22582261
* the unique rel cache here since we're possibly using a subset
22592262
* of join quals. We can use 'force_cache' == true when all join
22602263
* quals are self-join quals. Otherwise, we could end up putting

‎src/backend/optimizer/plan/setrefs.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ set_plan_references(PlannerInfo *root, Plan *plan)
307307
PlanRowMark*rc=lfirst_node(PlanRowMark,lc);
308308
PlanRowMark*newrc;
309309

310+
/* sanity check on existing row marks */
311+
Assert(root->simple_rel_array[rc->rti]!=NULL&&
312+
root->simple_rte_array[rc->rti]!=NULL);
313+
310314
/* flat copy is enough since all fields are scalars */
311315
newrc= (PlanRowMark*)palloc(sizeof(PlanRowMark));
312316
memcpy(newrc,rc,sizeof(PlanRowMark));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp