mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
Remove the Query structure from the executor's API. This allows us to stop
storing mostly-redundant Query trees in prepared statements, portals, etc. To replace Query, a new node type called PlannedStmt is inserted by the planner at the top of a completed plan tree; this carries just the fields of Query that are still needed at runtime. The statement lists kept in portals etc. now consist of intermixed PlannedStmt and bare utility-statement nodes --- no Query. This incidentally allows us to remove some fields from Query and Plan nodes that shouldn't have been there in the first place. Still to do: simplify the execution-time range table; at the moment the range table passed to the executor still contains Query trees for subqueries. initdb forced due to change of stored rules.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.366 2007/02/19 02:23:11 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.367 2007/02/20 17:32:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -64,6 +64,27 @@
|
||||
* ****************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* _copyPlannedStmt
|
||||
*/
|
||||
static PlannedStmt *
|
||||
_copyPlannedStmt(PlannedStmt *from)
|
||||
{
|
||||
PlannedStmt *newnode = makeNode(PlannedStmt);
|
||||
|
||||
COPY_SCALAR_FIELD(commandType);
|
||||
COPY_SCALAR_FIELD(canSetTag);
|
||||
COPY_NODE_FIELD(planTree);
|
||||
COPY_NODE_FIELD(rtable);
|
||||
COPY_NODE_FIELD(resultRelations);
|
||||
COPY_NODE_FIELD(into);
|
||||
COPY_NODE_FIELD(returningLists);
|
||||
COPY_NODE_FIELD(rowMarks);
|
||||
COPY_SCALAR_FIELD(nParamExec);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* CopyPlanFields
|
||||
*
|
||||
@@ -84,7 +105,6 @@ CopyPlanFields(Plan *from, Plan *newnode)
|
||||
COPY_NODE_FIELD(initPlan);
|
||||
COPY_BITMAPSET_FIELD(extParam);
|
||||
COPY_BITMAPSET_FIELD(allParam);
|
||||
COPY_SCALAR_FIELD(nParamExec);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -698,6 +718,23 @@ _copyRangeVar(RangeVar *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyIntoClause
|
||||
*/
|
||||
static IntoClause *
|
||||
_copyIntoClause(IntoClause *from)
|
||||
{
|
||||
IntoClause *newnode = makeNode(IntoClause);
|
||||
|
||||
COPY_NODE_FIELD(rel);
|
||||
COPY_NODE_FIELD(colNames);
|
||||
COPY_NODE_FIELD(options);
|
||||
COPY_SCALAR_FIELD(onCommit);
|
||||
COPY_STRING_FIELD(tableSpaceName);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't need a _copyExpr because Expr is an abstract supertype which
|
||||
* should never actually get instantiated. Also, since it has no common
|
||||
@@ -1762,9 +1799,6 @@ _copyQuery(Query *from)
|
||||
COPY_NODE_FIELD(utilityStmt);
|
||||
COPY_SCALAR_FIELD(resultRelation);
|
||||
COPY_NODE_FIELD(into);
|
||||
COPY_NODE_FIELD(intoOptions);
|
||||
COPY_SCALAR_FIELD(intoOnCommit);
|
||||
COPY_STRING_FIELD(intoTableSpaceName);
|
||||
COPY_SCALAR_FIELD(hasAggs);
|
||||
COPY_SCALAR_FIELD(hasSubLinks);
|
||||
COPY_NODE_FIELD(rtable);
|
||||
@@ -1779,8 +1813,6 @@ _copyQuery(Query *from)
|
||||
COPY_NODE_FIELD(limitCount);
|
||||
COPY_NODE_FIELD(rowMarks);
|
||||
COPY_NODE_FIELD(setOperations);
|
||||
COPY_NODE_FIELD(resultRelations);
|
||||
COPY_NODE_FIELD(returningLists);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@@ -1832,10 +1864,6 @@ _copySelectStmt(SelectStmt *from)
|
||||
|
||||
COPY_NODE_FIELD(distinctClause);
|
||||
COPY_NODE_FIELD(into);
|
||||
COPY_NODE_FIELD(intoColNames);
|
||||
COPY_NODE_FIELD(intoOptions);
|
||||
COPY_SCALAR_FIELD(intoOnCommit);
|
||||
COPY_STRING_FIELD(intoTableSpaceName);
|
||||
COPY_NODE_FIELD(targetList);
|
||||
COPY_NODE_FIELD(fromClause);
|
||||
COPY_NODE_FIELD(whereClause);
|
||||
@@ -2768,9 +2796,6 @@ _copyExecuteStmt(ExecuteStmt *from)
|
||||
|
||||
COPY_STRING_FIELD(name);
|
||||
COPY_NODE_FIELD(into);
|
||||
COPY_NODE_FIELD(intoOptions);
|
||||
COPY_SCALAR_FIELD(into_on_commit);
|
||||
COPY_STRING_FIELD(into_tbl_space);
|
||||
COPY_NODE_FIELD(params);
|
||||
|
||||
return newnode;
|
||||
@@ -2902,6 +2927,9 @@ copyObject(void *from)
|
||||
/*
|
||||
* PLAN NODES
|
||||
*/
|
||||
case T_PlannedStmt:
|
||||
retval = _copyPlannedStmt(from);
|
||||
break;
|
||||
case T_Plan:
|
||||
retval = _copyPlan(from);
|
||||
break;
|
||||
@@ -2990,6 +3018,9 @@ copyObject(void *from)
|
||||
case T_RangeVar:
|
||||
retval = _copyRangeVar(from);
|
||||
break;
|
||||
case T_IntoClause:
|
||||
retval = _copyIntoClause(from);
|
||||
break;
|
||||
case T_Var:
|
||||
retval = _copyVar(from);
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.298 2007/02/03 14:06:54 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.299 2007/02/20 17:32:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -102,6 +102,18 @@ _equalRangeVar(RangeVar *a, RangeVar *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalIntoClause(IntoClause *a, IntoClause *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(rel);
|
||||
COMPARE_NODE_FIELD(colNames);
|
||||
COMPARE_NODE_FIELD(options);
|
||||
COMPARE_SCALAR_FIELD(onCommit);
|
||||
COMPARE_STRING_FIELD(tableSpaceName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't need an _equalExpr because Expr is an abstract supertype which
|
||||
* should never actually get instantiated. Also, since it has no common
|
||||
@@ -690,9 +702,6 @@ _equalQuery(Query *a, Query *b)
|
||||
COMPARE_NODE_FIELD(utilityStmt);
|
||||
COMPARE_SCALAR_FIELD(resultRelation);
|
||||
COMPARE_NODE_FIELD(into);
|
||||
COMPARE_NODE_FIELD(intoOptions);
|
||||
COMPARE_SCALAR_FIELD(intoOnCommit);
|
||||
COMPARE_STRING_FIELD(intoTableSpaceName);
|
||||
COMPARE_SCALAR_FIELD(hasAggs);
|
||||
COMPARE_SCALAR_FIELD(hasSubLinks);
|
||||
COMPARE_NODE_FIELD(rtable);
|
||||
@@ -707,8 +716,6 @@ _equalQuery(Query *a, Query *b)
|
||||
COMPARE_NODE_FIELD(limitCount);
|
||||
COMPARE_NODE_FIELD(rowMarks);
|
||||
COMPARE_NODE_FIELD(setOperations);
|
||||
COMPARE_NODE_FIELD(resultRelations);
|
||||
COMPARE_NODE_FIELD(returningLists);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -752,10 +759,6 @@ _equalSelectStmt(SelectStmt *a, SelectStmt *b)
|
||||
{
|
||||
COMPARE_NODE_FIELD(distinctClause);
|
||||
COMPARE_NODE_FIELD(into);
|
||||
COMPARE_NODE_FIELD(intoColNames);
|
||||
COMPARE_NODE_FIELD(intoOptions);
|
||||
COMPARE_SCALAR_FIELD(intoOnCommit);
|
||||
COMPARE_STRING_FIELD(intoTableSpaceName);
|
||||
COMPARE_NODE_FIELD(targetList);
|
||||
COMPARE_NODE_FIELD(fromClause);
|
||||
COMPARE_NODE_FIELD(whereClause);
|
||||
@@ -1545,9 +1548,6 @@ _equalExecuteStmt(ExecuteStmt *a, ExecuteStmt *b)
|
||||
{
|
||||
COMPARE_STRING_FIELD(name);
|
||||
COMPARE_NODE_FIELD(into);
|
||||
COMPARE_NODE_FIELD(intoOptions);
|
||||
COMPARE_SCALAR_FIELD(into_on_commit);
|
||||
COMPARE_STRING_FIELD(into_tbl_space);
|
||||
COMPARE_NODE_FIELD(params);
|
||||
|
||||
return true;
|
||||
@@ -1967,6 +1967,9 @@ equal(void *a, void *b)
|
||||
case T_RangeVar:
|
||||
retval = _equalRangeVar(a, b);
|
||||
break;
|
||||
case T_IntoClause:
|
||||
retval = _equalIntoClause(a, b);
|
||||
break;
|
||||
case T_Var:
|
||||
retval = _equalVar(a, b);
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.299 2007/02/19 07:03:27 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.300 2007/02/20 17:32:15 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@@ -234,6 +234,22 @@ _outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
||||
* Stuff from plannodes.h
|
||||
*/
|
||||
|
||||
static void
|
||||
_outPlannedStmt(StringInfo str, PlannedStmt *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("PLANNEDSTMT");
|
||||
|
||||
WRITE_ENUM_FIELD(commandType, CmdType);
|
||||
WRITE_BOOL_FIELD(canSetTag);
|
||||
WRITE_NODE_FIELD(planTree);
|
||||
WRITE_NODE_FIELD(rtable);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(into);
|
||||
WRITE_NODE_FIELD(returningLists);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
WRITE_INT_FIELD(nParamExec);
|
||||
}
|
||||
|
||||
/*
|
||||
* print the basic stuff of all nodes that inherit from Plan
|
||||
*/
|
||||
@@ -251,7 +267,6 @@ _outPlanInfo(StringInfo str, Plan *node)
|
||||
WRITE_NODE_FIELD(initPlan);
|
||||
WRITE_BITMAPSET_FIELD(extParam);
|
||||
WRITE_BITMAPSET_FIELD(allParam);
|
||||
WRITE_INT_FIELD(nParamExec);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -635,6 +650,18 @@ _outRangeVar(StringInfo str, RangeVar *node)
|
||||
WRITE_NODE_FIELD(alias);
|
||||
}
|
||||
|
||||
static void
|
||||
_outIntoClause(StringInfo str, IntoClause *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("INTOCLAUSE");
|
||||
|
||||
WRITE_NODE_FIELD(rel);
|
||||
WRITE_NODE_FIELD(colNames);
|
||||
WRITE_NODE_FIELD(options);
|
||||
WRITE_ENUM_FIELD(onCommit, OnCommitAction);
|
||||
WRITE_STRING_FIELD(tableSpaceName);
|
||||
}
|
||||
|
||||
static void
|
||||
_outVar(StringInfo str, Var *node)
|
||||
{
|
||||
@@ -1245,6 +1272,8 @@ _outPlannerInfo(StringInfo str, PlannerInfo *node)
|
||||
WRITE_NODE_FIELD(glob);
|
||||
WRITE_UINT_FIELD(query_level);
|
||||
WRITE_NODE_FIELD(join_rel_list);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(returningLists);
|
||||
WRITE_NODE_FIELD(init_plans);
|
||||
WRITE_NODE_FIELD(eq_classes);
|
||||
WRITE_NODE_FIELD(canon_pathkeys);
|
||||
@@ -1502,10 +1531,6 @@ _outSelectStmt(StringInfo str, SelectStmt *node)
|
||||
|
||||
WRITE_NODE_FIELD(distinctClause);
|
||||
WRITE_NODE_FIELD(into);
|
||||
WRITE_NODE_FIELD(intoColNames);
|
||||
WRITE_NODE_FIELD(intoOptions);
|
||||
WRITE_ENUM_FIELD(intoOnCommit, OnCommitAction);
|
||||
WRITE_STRING_FIELD(intoTableSpaceName);
|
||||
WRITE_NODE_FIELD(targetList);
|
||||
WRITE_NODE_FIELD(fromClause);
|
||||
WRITE_NODE_FIELD(whereClause);
|
||||
@@ -1651,9 +1676,6 @@ _outQuery(StringInfo str, Query *node)
|
||||
|
||||
WRITE_INT_FIELD(resultRelation);
|
||||
WRITE_NODE_FIELD(into);
|
||||
WRITE_NODE_FIELD(intoOptions);
|
||||
WRITE_ENUM_FIELD(intoOnCommit, OnCommitAction);
|
||||
WRITE_STRING_FIELD(intoTableSpaceName);
|
||||
WRITE_BOOL_FIELD(hasAggs);
|
||||
WRITE_BOOL_FIELD(hasSubLinks);
|
||||
WRITE_NODE_FIELD(rtable);
|
||||
@@ -1668,8 +1690,6 @@ _outQuery(StringInfo str, Query *node)
|
||||
WRITE_NODE_FIELD(limitCount);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
WRITE_NODE_FIELD(setOperations);
|
||||
WRITE_NODE_FIELD(resultRelations);
|
||||
WRITE_NODE_FIELD(returningLists);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1988,6 +2008,9 @@ _outNode(StringInfo str, void *obj)
|
||||
appendStringInfoChar(str, '{');
|
||||
switch (nodeTag(obj))
|
||||
{
|
||||
case T_PlannedStmt:
|
||||
_outPlannedStmt(str, obj);
|
||||
break;
|
||||
case T_Plan:
|
||||
_outPlan(str, obj);
|
||||
break;
|
||||
@@ -2072,6 +2095,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_RangeVar:
|
||||
_outRangeVar(str, obj);
|
||||
break;
|
||||
case T_IntoClause:
|
||||
_outIntoClause(str, obj);
|
||||
break;
|
||||
case T_Var:
|
||||
_outVar(str, obj);
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.202 2007/02/03 14:06:54 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.203 2007/02/20 17:32:15 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@@ -140,9 +140,6 @@ _readQuery(void)
|
||||
READ_NODE_FIELD(utilityStmt);
|
||||
READ_INT_FIELD(resultRelation);
|
||||
READ_NODE_FIELD(into);
|
||||
READ_NODE_FIELD(intoOptions);
|
||||
READ_ENUM_FIELD(intoOnCommit, OnCommitAction);
|
||||
READ_STRING_FIELD(intoTableSpaceName);
|
||||
READ_BOOL_FIELD(hasAggs);
|
||||
READ_BOOL_FIELD(hasSubLinks);
|
||||
READ_NODE_FIELD(rtable);
|
||||
@@ -157,8 +154,6 @@ _readQuery(void)
|
||||
READ_NODE_FIELD(limitCount);
|
||||
READ_NODE_FIELD(rowMarks);
|
||||
READ_NODE_FIELD(setOperations);
|
||||
READ_NODE_FIELD(resultRelations);
|
||||
READ_NODE_FIELD(returningLists);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
@@ -287,6 +282,20 @@ _readRangeVar(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
static IntoClause *
|
||||
_readIntoClause(void)
|
||||
{
|
||||
READ_LOCALS(IntoClause);
|
||||
|
||||
READ_NODE_FIELD(rel);
|
||||
READ_NODE_FIELD(colNames);
|
||||
READ_NODE_FIELD(options);
|
||||
READ_ENUM_FIELD(onCommit, OnCommitAction);
|
||||
READ_STRING_FIELD(tableSpaceName);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readVar
|
||||
*/
|
||||
@@ -984,6 +993,8 @@ parseNodeString(void)
|
||||
return_value = _readAlias();
|
||||
else if (MATCH("RANGEVAR", 8))
|
||||
return_value = _readRangeVar();
|
||||
else if (MATCH("INTOCLAUSE", 10))
|
||||
return_value = _readIntoClause();
|
||||
else if (MATCH("VAR", 3))
|
||||
return_value = _readVar();
|
||||
else if (MATCH("CONST", 5))
|
||||
|
||||
Reference in New Issue
Block a user