mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +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:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.360 2007/02/01 19:10:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.361 2007/02/20 17:32:16 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -2143,11 +2143,8 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
if (stmt->into)
|
||||
{
|
||||
qry->into = stmt->into;
|
||||
if (stmt->intoColNames)
|
||||
applyColumnNames(qry->targetList, stmt->intoColNames);
|
||||
qry->intoOptions = copyObject(stmt->intoOptions);
|
||||
qry->intoOnCommit = stmt->intoOnCommit;
|
||||
qry->intoTableSpaceName = stmt->intoTableSpaceName;
|
||||
if (stmt->into->colNames)
|
||||
applyColumnNames(qry->targetList, stmt->into->colNames);
|
||||
}
|
||||
|
||||
qry->rtable = pstate->p_rtable;
|
||||
@@ -2315,11 +2312,8 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
|
||||
if (stmt->into)
|
||||
{
|
||||
qry->into = stmt->into;
|
||||
if (stmt->intoColNames)
|
||||
applyColumnNames(qry->targetList, stmt->intoColNames);
|
||||
qry->intoOptions = copyObject(stmt->intoOptions);
|
||||
qry->intoOnCommit = stmt->intoOnCommit;
|
||||
qry->intoTableSpaceName = stmt->intoTableSpaceName;
|
||||
if (stmt->into->colNames)
|
||||
applyColumnNames(qry->targetList, stmt->into->colNames);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2399,9 +2393,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
|
||||
/*
|
||||
* Find leftmost leaf SelectStmt; extract the one-time-only items from it
|
||||
* and from the top-level node. (Most of the INTO options can be
|
||||
* transferred to the Query immediately, but intoColNames has to be saved
|
||||
* to apply below.)
|
||||
* and from the top-level node.
|
||||
*/
|
||||
leftmostSelect = stmt->larg;
|
||||
while (leftmostSelect && leftmostSelect->op != SETOP_NONE)
|
||||
@@ -2411,10 +2403,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
|
||||
if (leftmostSelect->into)
|
||||
{
|
||||
qry->into = leftmostSelect->into;
|
||||
intoColNames = leftmostSelect->intoColNames;
|
||||
qry->intoOptions = copyObject(leftmostSelect->intoOptions);
|
||||
qry->intoOnCommit = leftmostSelect->intoOnCommit;
|
||||
qry->intoTableSpaceName = leftmostSelect->intoTableSpaceName;
|
||||
intoColNames = leftmostSelect->into->colNames;
|
||||
}
|
||||
|
||||
/* clear this to prevent complaints in transformSetOperationTree() */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.579 2007/02/03 14:06:54 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.580 2007/02/20 17:32:16 tgl Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -139,6 +139,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
|
||||
IndexElem *ielem;
|
||||
Alias *alias;
|
||||
RangeVar *range;
|
||||
IntoClause *into;
|
||||
A_Indices *aind;
|
||||
ResTarget *target;
|
||||
PrivTarget *privtarget;
|
||||
@@ -248,7 +249,8 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args)
|
||||
prep_type_clause
|
||||
execute_param_clause using_clause returning_clause
|
||||
|
||||
%type <range> into_clause OptTempTableName
|
||||
%type <range> OptTempTableName
|
||||
%type <into> into_clause create_as_target
|
||||
|
||||
%type <defelt> createfunc_opt_item common_func_opt_item
|
||||
%type <fun_param> func_arg
|
||||
@@ -2253,8 +2255,7 @@ OptConsTableSpace: USING INDEX TABLESPACE name { $$ = $4; }
|
||||
*/
|
||||
|
||||
CreateAsStmt:
|
||||
CREATE OptTemp TABLE qualified_name OptCreateAs
|
||||
OptWith OnCommitOption OptTableSpace AS SelectStmt
|
||||
CREATE OptTemp TABLE create_as_target AS SelectStmt
|
||||
{
|
||||
/*
|
||||
* When the SelectStmt is a set-operation tree, we must
|
||||
@@ -2263,18 +2264,26 @@ CreateAsStmt:
|
||||
* to find it. Similarly, the output column names must
|
||||
* be attached to that Select's target list.
|
||||
*/
|
||||
SelectStmt *n = findLeftmostSelect((SelectStmt *) $10);
|
||||
SelectStmt *n = findLeftmostSelect((SelectStmt *) $6);
|
||||
if (n->into != NULL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("CREATE TABLE AS cannot specify INTO")));
|
||||
$4->istemp = $2;
|
||||
$4->rel->istemp = $2;
|
||||
n->into = $4;
|
||||
n->intoColNames = $5;
|
||||
n->intoOptions = $6;
|
||||
n->intoOnCommit = $7;
|
||||
n->intoTableSpaceName = $8;
|
||||
$$ = $10;
|
||||
$$ = $6;
|
||||
}
|
||||
;
|
||||
|
||||
create_as_target:
|
||||
qualified_name OptCreateAs OptWith OnCommitOption OptTableSpace
|
||||
{
|
||||
$$ = makeNode(IntoClause);
|
||||
$$->rel = $1;
|
||||
$$->colNames = $2;
|
||||
$$->options = $3;
|
||||
$$->onCommit = $4;
|
||||
$$->tableSpaceName = $5;
|
||||
}
|
||||
;
|
||||
|
||||
@@ -5459,19 +5468,15 @@ ExecuteStmt: EXECUTE name execute_param_clause
|
||||
n->into = NULL;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| CREATE OptTemp TABLE qualified_name OptCreateAs
|
||||
OptWith OnCommitOption OptTableSpace AS
|
||||
| CREATE OptTemp TABLE create_as_target AS
|
||||
EXECUTE name execute_param_clause
|
||||
{
|
||||
ExecuteStmt *n = makeNode(ExecuteStmt);
|
||||
n->name = $11;
|
||||
n->params = $12;
|
||||
$4->istemp = $2;
|
||||
n->name = $7;
|
||||
n->params = $8;
|
||||
$4->rel->istemp = $2;
|
||||
n->into = $4;
|
||||
n->intoOptions = $6;
|
||||
n->into_on_commit = $7;
|
||||
n->into_tbl_space = $8;
|
||||
if ($5)
|
||||
if ($4->colNames)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("column name list not allowed in CREATE TABLE / AS EXECUTE")));
|
||||
@@ -5854,7 +5859,6 @@ simple_select:
|
||||
n->distinctClause = $2;
|
||||
n->targetList = $3;
|
||||
n->into = $4;
|
||||
n->intoColNames = NIL;
|
||||
n->fromClause = $5;
|
||||
n->whereClause = $6;
|
||||
n->groupClause = $7;
|
||||
@@ -5877,8 +5881,17 @@ simple_select:
|
||||
;
|
||||
|
||||
into_clause:
|
||||
INTO OptTempTableName { $$ = $2; }
|
||||
| /*EMPTY*/ { $$ = NULL; }
|
||||
INTO OptTempTableName
|
||||
{
|
||||
$$ = makeNode(IntoClause);
|
||||
$$->rel = $2;
|
||||
$$->colNames = NIL;
|
||||
$$->options = NIL;
|
||||
$$->onCommit = ONCOMMIT_NOOP;
|
||||
$$->tableSpaceName = NULL;
|
||||
}
|
||||
| /*EMPTY*/
|
||||
{ $$ = NULL; }
|
||||
;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user