Skip to content

Commit e0345e0

Browse files
committed
Partial fix for copied-plan bugs reported by Hiroshi Inoue:
_copyResult didn't copy subPlan structure completely. _copyAgg is still busted, apparently because of changes from EXCEPT/INTERSECT patch (get_agg_tlist_references is no longer sufficient to find all aggregates). No time to look at that tonight, however.
1 parent b204d10 commit e0345e0

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.75 1999/03/01 00:10:30 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.76 1999/03/03 00:02:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -30,6 +30,7 @@
3030
#include "catalog/pg_type.h"
3131
#include "storage/lmgr.h"
3232
#include "optimizer/planmain.h"
33+
#include "optimizer/subselect.h"
3334

3435
/*
3536
* listCopy
@@ -78,8 +79,6 @@ listCopy(List *list)
7879
static void
7980
CopyPlanFields(Plan *from, Plan *newnode)
8081
{
81-
extern List *SS_pull_subplan(void *expr);
82-
8382
newnode->cost = from->cost;
8483
newnode->plan_size = from->plan_size;
8584
newnode->plan_width = from->plan_width;
@@ -93,7 +92,7 @@ CopyPlanFields(Plan *from, Plan *newnode)
9392
newnode->chgParam = listCopy(from->chgParam);
9493
Node_Copy(from, newnode, initPlan);
9594
if (from->subPlan != NULL)
96-
newnode->subPlan = SS_pull_subplan(newnode->qual);
95+
newnode->subPlan = SS_pull_subplan((Node*) newnode->qual);
9796
else
9897
newnode->subPlan = NULL;
9998
newnode->nParamExec = from->nParamExec;
@@ -139,6 +138,11 @@ _copyResult(Result *from)
139138
*/
140139
Node_Copy(from, newnode, resconstantqual);
141140

141+
/* We must add subplans in resconstantqual to the new plan's subPlan list
142+
*/
143+
newnode->plan.subPlan = nconc(newnode->plan.subPlan,
144+
SS_pull_subplan(newnode->resconstantqual));
145+
142146
return newnode;
143147
}
144148

src/backend/optimizer/plan/subselect.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ SS_finalize_plan(Plan *plan)
426426
case T_Result:
427427
param_list = set_unioni(param_list,
428428
_finalize_primnode(((Result *) plan)->resconstantqual, &subPlan));
429+
/* subPlan is NOT necessarily NULL here ... */
429430
break;
430431

431432
case T_Append:
@@ -503,10 +504,10 @@ SS_finalize_plan(Plan *plan)
503504

504505
}
505506

506-
List *SS_pull_subplan(void *expr);
507+
/* Construct a list of all subplans found within the given node tree */
507508

508509
List *
509-
SS_pull_subplan(void *expr)
510+
SS_pull_subplan(Node *expr)
510511
{
511512
List *result = NULL;
512513

@@ -524,18 +525,18 @@ SS_pull_subplan(void *expr)
524525
return SS_pull_subplan(((Iter *) expr)->iterexpr);
525526
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
526527
not_clause(expr) || is_funcclause(expr))
527-
return SS_pull_subplan(((Expr *) expr)->args);
528+
return SS_pull_subplan((Node *) ((Expr *) expr)->args);
528529
else if (IsA(expr, Aggref))
529530
return SS_pull_subplan(((Aggref *) expr)->target);
530531
else if (IsA(expr, ArrayRef))
531532
{
532-
result = SS_pull_subplan(((ArrayRef *) expr)->refupperindexpr);
533+
result = SS_pull_subplan((Node *)((ArrayRef *) expr)->refupperindexpr);
533534
result = nconc(result,
534-
SS_pull_subplan(((ArrayRef *) expr)->reflowerindexpr));
535+
SS_pull_subplan((Node*) ((ArrayRef *) expr)->reflowerindexpr));
535536
result = nconc(result,
536537
SS_pull_subplan(((ArrayRef *) expr)->refexpr));
537538
result = nconc(result,
538-
SS_pull_subplan(((ArrayRef *) expr)->refassgnexpr));
539+
SS_pull_subplan(((ArrayRef *) expr)->refassgnexpr));
539540
}
540541
else if (IsA(expr, TargetEntry))
541542
return SS_pull_subplan(((TargetEntry *) expr)->expr);

src/include/optimizer/subselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ extern int PlannerPlanId; /* to assigne unique ID to subquery plans */
1616
extern List *SS_finalize_plan(Plan *plan);
1717
extern Node *SS_replace_correlation_vars(Node *expr);
1818
extern Node *SS_process_sublinks(Node *expr);
19+
extern List *SS_pull_subplan(Node *expr);
1920

2021
#endif /* SUBSELECT_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy