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

Commit147fbf9

Browse files
committed
Repair bug reported by Laurent Perez: bad plan generated when UPDATE or
DELETE of an inheritance tree references another inherited relation.This bug has been latent since 7.1; I'm still not quite sure why 7.1 and7.2 don't manifest it (at least, they don't crash on a simple test case).
1 parent391eb5e commit147fbf9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.148 2003/02/15 21:39:58 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.149 2003/03/05 18:38:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -443,6 +443,7 @@ inheritance_planner(Query *parse, List *inheritlist)
443443
{
444444
intparentRTindex=parse->resultRelation;
445445
OidparentOID=getrelid(parentRTindex,parse->rtable);
446+
intmainrtlength=length(parse->rtable);
446447
List*subplans=NIL;
447448
List*tlist=NIL;
448449
List*l;
@@ -451,6 +452,7 @@ inheritance_planner(Query *parse, List *inheritlist)
451452
{
452453
intchildRTindex=lfirsti(l);
453454
OidchildOID=getrelid(childRTindex,parse->rtable);
455+
intsubrtlength;
454456
Query*subquery;
455457
Plan*subplan;
456458

@@ -461,6 +463,24 @@ inheritance_planner(Query *parse, List *inheritlist)
461463
/* Generate plan */
462464
subplan=grouping_planner(subquery,0.0/* retrieve all tuples */ );
463465
subplans=lappend(subplans,subplan);
466+
/*
467+
* It's possible that additional RTEs got added to the rangetable
468+
* due to expansion of inherited source tables (see allpaths.c).
469+
* If so, we must copy 'em back to the main parse tree's rtable.
470+
*
471+
* XXX my goodness this is ugly. Really need to think about ways
472+
* to rein in planner's habit of scribbling on its input.
473+
*/
474+
subrtlength=length(subquery->rtable);
475+
if (subrtlength>mainrtlength)
476+
{
477+
List*subrt=subquery->rtable;
478+
479+
while (mainrtlength-->0)/* wish we had nthcdr() */
480+
subrt=lnext(subrt);
481+
parse->rtable=nconc(parse->rtable,subrt);
482+
mainrtlength=subrtlength;
483+
}
464484
/* Save preprocessed tlist from first rel for use in Append */
465485
if (tlist==NIL)
466486
tlist=subplan->targetlist;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp