aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-12-14 00:17:59 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-12-14 00:17:59 +0000
commit2d8d66628a8ac49deba8483608135b3c358ae729 (patch)
tree95f321c5fc2035b5110317e25b0449e85065c8a5 /src/include
parent29cdab3d531b6f612ab53b93dbb34a131e9cdb1c (diff)
downloadpostgresql-2d8d66628a8ac49deba8483608135b3c358ae729.tar.gz
postgresql-2d8d66628a8ac49deba8483608135b3c358ae729.zip
Clean up plantree representation of SubPlan-s --- SubLink does not appear
in the planned representation of a subplan at all any more, only SubPlan. This means subselect.c doesn't scribble on its input anymore, which seems like a good thing; and there are no longer three different possible interpretations of a SubLink. Simplify node naming and improve comments in primnodes.h. No change to stored rules, though.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/executor/executor.h5
-rw-r--r--src/include/executor/nodeSubplan.h12
-rw-r--r--src/include/nodes/execnodes.h17
-rw-r--r--src/include/nodes/nodes.h6
-rw-r--r--src/include/nodes/params.h6
-rw-r--r--src/include/nodes/primnodes.h88
-rw-r--r--src/include/optimizer/clauses.h4
7 files changed, 72 insertions, 66 deletions
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index bdcb3a6afa5..9b7af6d36fb 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: executor.h,v 1.82 2002/12/13 19:45:56 tgl Exp $
+ * $Id: executor.h,v 1.83 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -92,8 +92,7 @@ extern Datum ExecEvalExpr(ExprState *expression, ExprContext *econtext,
extern Datum ExecEvalExprSwitchContext(ExprState *expression, ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone);
extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
-extern SubPlanExprState *ExecInitExprInitPlan(SubPlanExpr *node,
- PlanState *parent);
+extern SubPlanState *ExecInitExprInitPlan(SubPlan *node, PlanState *parent);
extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull);
extern int ExecTargetListLength(List *targetlist);
extern int ExecCleanTargetListLength(List *targetlist);
diff --git a/src/include/executor/nodeSubplan.h b/src/include/executor/nodeSubplan.h
index 97f4b66bcd6..8a3e74ebd1c 100644
--- a/src/include/executor/nodeSubplan.h
+++ b/src/include/executor/nodeSubplan.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: nodeSubplan.h,v 1.14 2002/12/13 19:45:56 tgl Exp $
+ * $Id: nodeSubplan.h,v 1.15 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,13 +16,13 @@
#include "nodes/execnodes.h"
-extern void ExecInitSubPlan(SubPlanExprState *sstate, EState *estate);
-extern Datum ExecSubPlan(SubPlanExprState *node,
+extern void ExecInitSubPlan(SubPlanState *node, EState *estate);
+extern Datum ExecSubPlan(SubPlanState *node,
ExprContext *econtext,
bool *isNull);
-extern void ExecEndSubPlan(SubPlanExprState *node);
-extern void ExecReScanSetParamPlan(SubPlanExprState *node, PlanState *parent);
+extern void ExecEndSubPlan(SubPlanState *node);
+extern void ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent);
-extern void ExecSetParamPlan(SubPlanExprState *node, ExprContext *econtext);
+extern void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext);
#endif /* NODESUBPLAN_H */
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 905bfae6d87..f8e1f7cc4c9 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: execnodes.h,v 1.84 2002/12/13 19:45:57 tgl Exp $
+ * $Id: execnodes.h,v 1.85 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -451,21 +451,18 @@ typedef struct BoolExprState
} BoolExprState;
/* ----------------
- * SubPlanExprState node
- *
- * Note: there is no separate ExprState node for the SubLink. All it would
- * need is the oper field, which we can just as easily put here.
+ * SubPlanState node
* ----------------
*/
-typedef struct SubPlanExprState
+typedef struct SubPlanState
{
ExprState xprstate;
struct PlanState *planstate; /* subselect plan's state tree */
bool needShutdown; /* TRUE = need to shutdown subplan */
HeapTuple curTuple; /* copy of most recent tuple from subplan */
- List *args; /* states of argument expression(s) */
List *oper; /* states for executable combining exprs */
-} SubPlanExprState;
+ List *args; /* states of argument expression(s) */
+} SubPlanState;
/* ----------------
* CaseExprState node
@@ -538,9 +535,9 @@ typedef struct PlanState
List *qual; /* implicitly-ANDed qual conditions */
struct PlanState *lefttree; /* input plan tree(s) */
struct PlanState *righttree;
- List *initPlan; /* Init SubPlanExprState nodes (un-correlated
+ List *initPlan; /* Init SubPlanState nodes (un-correlated
* expr subselects) */
- List *subPlan; /* SubPlanExprState nodes in my expressions */
+ List *subPlan; /* SubPlanState nodes in my expressions */
/*
* State for management of parameter-change-driven rescanning
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index cc550131852..5f628168738 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: nodes.h,v 1.132 2002/12/13 19:46:00 tgl Exp $
+ * $Id: nodes.h,v 1.133 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -107,7 +107,7 @@ typedef enum NodeTag
T_DistinctExpr,
T_BoolExpr,
T_SubLink,
- T_SubPlanExpr,
+ T_SubPlan,
T_FieldSelect,
T_RelabelType,
T_CaseExpr,
@@ -133,7 +133,7 @@ typedef enum NodeTag
T_ArrayRefExprState,
T_FuncExprState,
T_BoolExprState,
- T_SubPlanExprState,
+ T_SubPlanState,
T_CaseExprState,
T_CaseWhenState,
T_ConstraintTestState,
diff --git a/src/include/nodes/params.h b/src/include/nodes/params.h
index c8bc2857ed8..8d7aa3ab32b 100644
--- a/src/include/nodes/params.h
+++ b/src/include/nodes/params.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: params.h,v 1.20 2002/12/13 19:46:00 tgl Exp $
+ * $Id: params.h,v 1.21 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -88,7 +88,7 @@ typedef ParamListInfoData *ParamListInfo;
* array of ParamExecData records, which is referenced through
* es_param_exec_vals or ecxt_param_exec_vals.
*
- * If execPlan is not NULL, it points to a SubPlanExprState node that needs
+ * If execPlan is not NULL, it points to a SubPlanState node that needs
* to be executed to produce the value. (This is done so that we can have
* lazy evaluation of InitPlans: they aren't executed until/unless a
* result value is needed.) Otherwise the value is assumed to be valid
@@ -98,7 +98,7 @@ typedef ParamListInfoData *ParamListInfo;
typedef struct ParamExecData
{
- void *execPlan; /* should be "SubPlanExprState *" */
+ void *execPlan; /* should be "SubPlanState *" */
Datum value;
bool isnull;
} ParamExecData;
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index 01a6dbf8d64..285a0008fdc 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: primnodes.h,v 1.74 2002/12/13 19:46:00 tgl Exp $
+ * $Id: primnodes.h,v 1.75 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -378,32 +378,21 @@ typedef struct BoolExpr
* using AND and OR semantics respectively.
*
* SubLink is classed as an Expr node, but it is not actually executable;
- * it must be replaced in the expression tree by a SubPlanExpr node during
+ * it must be replaced in the expression tree by a SubPlan node during
* planning.
*
- * NOTE: lefthand and oper have varying meanings depending on where you look
- * in the parse/plan pipeline:
- * 1. gram.y delivers a list of the (untransformed) lefthand expressions in
- * lefthand, and sets oper to a single A_Expr (not a list!) containing
- * the string name of the operator, but no arguments.
- * 2. The parser's expression transformation transforms lefthand normally,
- * and replaces oper with a list of OpExpr nodes, one per lefthand
- * expression. These nodes represent the parser's resolution of exactly
- * which operator to apply to each pair of lefthand and targetlist
- * expressions. However, we have not constructed complete Expr trees for
- * these operations yet: the args fields of the OpExpr nodes are NIL.
- * This is the representation seen in saved rules and in the rewriter.
- * 3. Finally, the planner converts the oper list to a list of normal OpExpr
- * nodes representing the application of the operator(s) to the lefthand
- * expressions and values from the inner targetlist. The inner
- * targetlist items are represented by placeholder Param nodes.
- * The lefthand field is set to NIL, since its expressions are now in
- * the Expr list. This representation is passed to the executor.
- *
- * Planner routines that might see either representation 2 or 3 can tell
- * the difference by checking whether lefthand is NIL or not. Also,
- * representation 2 appears in a "bare" SubLink, while representation 3 is
- * found in SubLinks that are children of SubPlanExpr nodes.
+ * NOTE: in the raw output of gram.y, lefthand contains a list of (raw)
+ * expressions, and oper contains a single A_Expr (not a list!) containing
+ * the string name of the operator, but no arguments. Also, subselect is
+ * a raw parsetree. During parse analysis, the parser transforms the
+ * lefthand expression list using normal expression transformation rules.
+ * It replaces oper with a list of OpExpr nodes, one per lefthand expression.
+ * These nodes represent the parser's resolution of exactly which operator
+ * to apply to each pair of lefthand and targetlist expressions. However,
+ * we have not constructed complete Expr trees for these operations yet:
+ * the args fields of the OpExpr nodes are NIL. And subselect is transformed
+ * to a Query. This is the representation seen in saved rules and in the
+ * rewriter.
*
* In EXISTS and EXPR SubLinks, both lefthand and oper are unused and are
* always NIL. useor is not significant either for these sublink types.
@@ -423,37 +412,58 @@ typedef struct SubLink
* "OR" not "AND" */
List *lefthand; /* list of outer-query expressions on the
* left */
- List *oper; /* list of OpExpr nodes for combining
- * operators, or final list of executable
- * expressions */
+ List *oper; /* list of arg-less OpExpr nodes for
+ * combining operators */
Node *subselect; /* subselect as Query* or parsetree */
} SubLink;
/*
- * SubPlanExpr - executable expression node for a subplan (sub-SELECT)
- *
- * The planner replaces SubLink nodes in expression trees with SubPlanExpr
- * nodes after it has finished planning the subquery. See notes above.
- */
-typedef struct SubPlanExpr
+ * SubPlan - executable expression node for a subplan (sub-SELECT)
+ *
+ * The planner replaces SubLink nodes in expression trees with SubPlan
+ * nodes after it has finished planning the subquery. SubPlan contains
+ * a sub-plantree and rtable instead of a sub-Query. Its "oper" field
+ * corresponds to the original SubLink's oper list, but has been expanded
+ * into valid executable expressions representing the application of the
+ * combining operator(s) to the lefthand expressions and values from the
+ * inner targetlist. The original lefthand expressions now appear as
+ * left-hand arguments of the OpExpr nodes, while the inner targetlist items
+ * are represented by PARAM_EXEC Param nodes. (Note: if the sub-select
+ * becomes an InitPlan rather than a SubPlan, the rebuilt oper list is
+ * part of the outer plan tree and so is not stored in the oper field.)
+ *
+ * The planner also derives lists of the values that need to be passed into
+ * and out of the subplan. Input values are represented as a list "args" of
+ * expressions to be evaluated in the outer-query context (currently these
+ * args are always just Vars, but in principle they could be any expression).
+ * The values are assigned to the global PARAM_EXEC params indexed by parParam
+ * (the parParam and args lists must have the same length). setParam is a
+ * list of the PARAM_EXEC params that are computed by the sub-select, if it
+ * is an initPlan.
+ */
+typedef struct SubPlan
{
Expr xpr;
- Oid typeOid; /* PG_TYPE OID of the expression result */
+ /* Fields copied from original SubLink: */
+ SubLinkType subLinkType; /* EXISTS, ALL, ANY, MULTIEXPR, EXPR */
+ bool useor; /* TRUE to combine column results with
+ * "OR" not "AND" */
+ List *oper; /* list of executable expressions for
+ * combining operators (with arguments) */
+ /* The subselect, transformed to a Plan: */
struct Plan *plan; /* subselect plan itself */
int plan_id; /* dummy thing because of we haven't equal
* funcs for plan nodes... actually, we
* could put *plan itself somewhere else
* (TopPlan node ?)... */
List *rtable; /* range table for subselect */
+ /* Information for passing params into and out of the subselect: */
/* setParam and parParam are lists of integers (param IDs) */
List *setParam; /* non-correlated EXPR & EXISTS subqueries
* have to set some Params for paren Plan */
List *parParam; /* indices of input Params from parent plan */
List *args; /* exprs to pass as parParam values */
- SubLink *sublink; /* SubLink node from parser; holds info
- * about what to do with subselect's
- * results */
-} SubPlanExpr;
+} SubPlan;
/* ----------------
* FieldSelect
diff --git a/src/include/optimizer/clauses.h b/src/include/optimizer/clauses.h
index 8da7a8688ef..f280e420d9b 100644
--- a/src/include/optimizer/clauses.h
+++ b/src/include/optimizer/clauses.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: clauses.h,v 1.57 2002/12/12 15:49:41 tgl Exp $
+ * $Id: clauses.h,v 1.58 2002/12/14 00:17:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,7 +20,7 @@
#define is_opclause(clause) ((clause) != NULL && IsA(clause, OpExpr))
#define is_funcclause(clause) ((clause) != NULL && IsA(clause, FuncExpr))
-#define is_subplan(clause) ((clause) != NULL && IsA(clause, SubPlanExpr))
+#define is_subplan(clause) ((clause) != NULL && IsA(clause, SubPlan))
extern Expr *make_opclause(Oid opno, Oid opresulttype, bool opretset,