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.
This commit is contained in:
Tom Lane 1999-03-03 00:02:42 +00:00
parent b204d10c79
commit e0345e09bf
3 changed files with 16 additions and 10 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.75 1999/03/01 00:10:30 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.76 1999/03/03 00:02:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -30,6 +30,7 @@
#include "catalog/pg_type.h"
#include "storage/lmgr.h"
#include "optimizer/planmain.h"
#include "optimizer/subselect.h"
/*
* listCopy
@ -78,8 +79,6 @@ listCopy(List *list)
static void
CopyPlanFields(Plan *from, Plan *newnode)
{
extern List *SS_pull_subplan(void *expr);
newnode->cost = from->cost;
newnode->plan_size = from->plan_size;
newnode->plan_width = from->plan_width;
@ -93,7 +92,7 @@ CopyPlanFields(Plan *from, Plan *newnode)
newnode->chgParam = listCopy(from->chgParam);
Node_Copy(from, newnode, initPlan);
if (from->subPlan != NULL)
newnode->subPlan = SS_pull_subplan(newnode->qual);
newnode->subPlan = SS_pull_subplan((Node*) newnode->qual);
else
newnode->subPlan = NULL;
newnode->nParamExec = from->nParamExec;
@ -139,6 +138,11 @@ _copyResult(Result *from)
*/
Node_Copy(from, newnode, resconstantqual);
/* We must add subplans in resconstantqual to the new plan's subPlan list
*/
newnode->plan.subPlan = nconc(newnode->plan.subPlan,
SS_pull_subplan(newnode->resconstantqual));
return newnode;
}

View File

@ -426,6 +426,7 @@ SS_finalize_plan(Plan *plan)
case T_Result:
param_list = set_unioni(param_list,
_finalize_primnode(((Result *) plan)->resconstantqual, &subPlan));
/* subPlan is NOT necessarily NULL here ... */
break;
case T_Append:
@ -503,10 +504,10 @@ SS_finalize_plan(Plan *plan)
}
List *SS_pull_subplan(void *expr);
/* Construct a list of all subplans found within the given node tree */
List *
SS_pull_subplan(void *expr)
SS_pull_subplan(Node *expr)
{
List *result = NULL;
@ -524,18 +525,18 @@ SS_pull_subplan(void *expr)
return SS_pull_subplan(((Iter *) expr)->iterexpr);
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
not_clause(expr) || is_funcclause(expr))
return SS_pull_subplan(((Expr *) expr)->args);
return SS_pull_subplan((Node *) ((Expr *) expr)->args);
else if (IsA(expr, Aggref))
return SS_pull_subplan(((Aggref *) expr)->target);
else if (IsA(expr, ArrayRef))
{
result = SS_pull_subplan(((ArrayRef *) expr)->refupperindexpr);
result = SS_pull_subplan((Node *)((ArrayRef *) expr)->refupperindexpr);
result = nconc(result,
SS_pull_subplan(((ArrayRef *) expr)->reflowerindexpr));
SS_pull_subplan((Node*) ((ArrayRef *) expr)->reflowerindexpr));
result = nconc(result,
SS_pull_subplan(((ArrayRef *) expr)->refexpr));
result = nconc(result,
SS_pull_subplan(((ArrayRef *) expr)->refassgnexpr));
SS_pull_subplan(((ArrayRef *) expr)->refassgnexpr));
}
else if (IsA(expr, TargetEntry))
return SS_pull_subplan(((TargetEntry *) expr)->expr);

View File

@ -16,5 +16,6 @@ extern int PlannerPlanId; /* to assigne unique ID to subquery plans */
extern List *SS_finalize_plan(Plan *plan);
extern Node *SS_replace_correlation_vars(Node *expr);
extern Node *SS_process_sublinks(Node *expr);
extern List *SS_pull_subplan(Node *expr);
#endif /* SUBSELECT_H */