summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-20 17:32:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-20 17:32:18 +0000
commit9cbd0c155d1602aad879f510256b626c58942080 (patch)
tree6d5504a4e841313d3a29cead80067006dc408e39 /src/include
parent71b0cf2f6bec3129f2c3f574d4e47408c2dc2516 (diff)
downloadpostgresql-9cbd0c155d1602aad879f510256b626c58942080.tar.gz
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.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/catversion.h4
-rw-r--r--src/include/commands/portalcmds.h3
-rw-r--r--src/include/commands/prepare.h16
-rw-r--r--src/include/executor/execdesc.h21
-rw-r--r--src/include/executor/executor.h3
-rw-r--r--src/include/executor/spi_priv.h11
-rw-r--r--src/include/nodes/execnodes.h4
-rw-r--r--src/include/nodes/nodes.h20
-rw-r--r--src/include/nodes/parsenodes.h62
-rw-r--r--src/include/nodes/plannodes.h53
-rw-r--r--src/include/nodes/primnodes.h25
-rw-r--r--src/include/nodes/relation.h6
-rw-r--r--src/include/optimizer/planner.h6
-rw-r--r--src/include/tcop/pquery.h7
-rw-r--r--src/include/tcop/tcopprot.h5
-rw-r--r--src/include/tcop/utility.h10
-rw-r--r--src/include/utils/portal.h16
17 files changed, 153 insertions, 119 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 20d6e24e05..8c53a2df2a 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.387 2007/02/20 10:00:25 petere Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.388 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200702201
+#define CATALOG_VERSION_NO 200702202
#endif
diff --git a/src/include/commands/portalcmds.h b/src/include/commands/portalcmds.h
index 4a17ddb767..50fe2f1328 100644
--- a/src/include/commands/portalcmds.h
+++ b/src/include/commands/portalcmds.h
@@ -7,13 +7,14 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/portalcmds.h,v 1.20 2007/01/05 22:19:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/portalcmds.h,v 1.21 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PORTALCMDS_H
#define PORTALCMDS_H
+#include "nodes/parsenodes.h"
#include "utils/portal.h"
diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h
index c1ee47fe7e..a921bf1b04 100644
--- a/src/include/commands/prepare.h
+++ b/src/include/commands/prepare.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.23 2007/01/05 22:19:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.24 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -19,6 +19,10 @@
/*
* The data structure representing a prepared statement
*
+ * A prepared statement might be fully planned, or only parsed-and-rewritten.
+ * If fully planned, stmt_list contains PlannedStmts and/or utility statements;
+ * if not, it contains Query nodes.
+ *
* Note: all subsidiary storage lives in the context denoted by the context
* field. However, the string referenced by commandTag is not subsidiary
* storage; it is assumed to be a compile-time-constant string. As with
@@ -31,11 +35,11 @@ typedef struct
char stmt_name[NAMEDATALEN];
char *query_string; /* text of query, or NULL */
const char *commandTag; /* command tag (a constant!), or NULL */
- List *query_list; /* list of queries, rewritten */
- List *plan_list; /* list of plans */
+ List *stmt_list; /* list of statement or Query nodes */
List *argtype_list; /* list of parameter type OIDs */
+ bool fully_planned; /* what is in stmt_list, exactly? */
+ bool from_sql; /* prepared via SQL, not FE/BE protocol? */
TimestampTz prepare_time; /* the time when the stmt was prepared */
- bool from_sql; /* stmt prepared via SQL, not FE/BE protocol? */
MemoryContext context; /* context containing this query */
} PreparedStatement;
@@ -52,9 +56,9 @@ extern void ExplainExecuteQuery(ExplainStmt *stmt, ParamListInfo params,
extern void StorePreparedStatement(const char *stmt_name,
const char *query_string,
const char *commandTag,
- List *query_list,
- List *plan_list,
+ List *stmt_list,
List *argtype_list,
+ bool fully_planned,
bool from_sql);
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
bool throwError);
diff --git a/src/include/executor/execdesc.h b/src/include/executor/execdesc.h
index cf991125d4..d5ae745a29 100644
--- a/src/include/executor/execdesc.h
+++ b/src/include/executor/execdesc.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/executor/execdesc.h,v 1.33 2007/01/05 22:19:54 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/executor/execdesc.h,v 1.34 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -16,7 +16,7 @@
#define EXECDESC_H
#include "nodes/execnodes.h"
-#include "nodes/parsenodes.h"
+#include "nodes/plannodes.h"
#include "tcop/dest.h"
@@ -24,15 +24,19 @@
* query descriptor:
*
* a QueryDesc encapsulates everything that the executor
- * needs to execute the query
+ * needs to execute the query.
+ *
+ * For the convenience of SQL-language functions, we also support QueryDescs
+ * containing utility statements; these must not be passed to the executor
+ * however.
* ---------------------
*/
typedef struct QueryDesc
{
/* These fields are provided by CreateQueryDesc */
CmdType operation; /* CMD_SELECT, CMD_UPDATE, etc. */
- Query *parsetree; /* rewritten parsetree */
- Plan *plantree; /* planner's output */
+ PlannedStmt *plannedstmt; /* planner's output, or null if utility */
+ Node *utilitystmt; /* utility statement, or null */
Snapshot snapshot; /* snapshot to use for query */
Snapshot crosscheck_snapshot; /* crosscheck for RI update/delete */
DestReceiver *dest; /* the destination for tuple output */
@@ -46,13 +50,18 @@ typedef struct QueryDesc
} QueryDesc;
/* in pquery.c */
-extern QueryDesc *CreateQueryDesc(Query *parsetree, Plan *plantree,
+extern QueryDesc *CreateQueryDesc(PlannedStmt *plannedstmt,
Snapshot snapshot,
Snapshot crosscheck_snapshot,
DestReceiver *dest,
ParamListInfo params,
bool doInstrument);
+extern QueryDesc *CreateUtilityQueryDesc(Node *utilitystmt,
+ Snapshot snapshot,
+ DestReceiver *dest,
+ ParamListInfo params);
+
extern void FreeQueryDesc(QueryDesc *qdesc);
#endif /* EXECDESC_H */
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index bfbe1ba2f3..38260b5ecd 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.136 2007/02/06 02:59:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.137 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,6 +15,7 @@
#define EXECUTOR_H
#include "executor/execdesc.h"
+#include "nodes/parsenodes.h"
/*
diff --git a/src/include/executor/spi_priv.h b/src/include/executor/spi_priv.h
index 3bfc870159..5e65bd750a 100644
--- a/src/include/executor/spi_priv.h
+++ b/src/include/executor/spi_priv.h
@@ -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/include/executor/spi_priv.h,v 1.26 2007/01/05 22:19:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/executor/spi_priv.h,v 1.27 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -35,10 +35,11 @@ typedef struct
MemoryContext plancxt;
/* Original query string (used for error reporting) */
const char *query;
- /* List of List of querytrees; one sublist per original parsetree */
- List *qtlist;
- /* List of plan trees --- length == # of querytrees, but flat list */
- List *ptlist;
+ /*
+ * List of List of PlannedStmts and utility stmts; one sublist per
+ * original parsetree
+ */
+ List *stmt_list_list;
/* Argument types, if a prepared plan */
int nargs;
Oid *argtypes;
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 35a0ab3a60..b576f4610e 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.167 2007/02/06 02:59:13 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.168 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -344,7 +344,7 @@ typedef struct EState
ExprContext *es_per_tuple_exprcontext;
/* Below is to re-evaluate plan qual in READ COMMITTED mode */
- Plan *es_topPlan; /* link to top of plan tree */
+ PlannedStmt *es_plannedstmt; /* link to top of plan tree */
struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual states */
bool *es_evTupleNull; /* local array of EPQ status */
HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index 44175591e7..53bd13b5fb 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.195 2007/02/19 07:03:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.196 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -141,6 +141,7 @@ typedef enum NodeTag
T_RangeTblRef,
T_JoinExpr,
T_FromExpr,
+ T_IntoClause,
/*
* TAGS FOR EXPRESSION STATE NODES (execnodes.h)
@@ -225,9 +226,10 @@ typedef enum NodeTag
T_OidList,
/*
- * TAGS FOR PARSE TREE NODES (parsenodes.h)
+ * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
*/
T_Query = 700,
+ T_PlannedStmt,
T_InsertStmt,
T_DeleteStmt,
T_UpdateStmt,
@@ -302,8 +304,12 @@ typedef enum NodeTag
T_AlterOwnerStmt,
T_DropOwnedStmt,
T_ReassignOwnedStmt,
+ T_CompositeTypeStmt,
- T_A_Expr = 800,
+ /*
+ * TAGS FOR PARSE TREE NODES (parsenodes.h)
+ */
+ T_A_Expr = 900,
T_ColumnRef,
T_ParamRef,
T_A_Const,
@@ -328,7 +334,6 @@ typedef enum NodeTag
T_FuncWithArgs,
T_PrivTarget,
T_CreateOpClassItem,
- T_CompositeTypeStmt,
T_InhRelation,
T_FunctionParameter,
T_LockingClause,
@@ -343,7 +348,7 @@ typedef enum NodeTag
* purposes (usually because they are involved in APIs where we want to
* pass multiple object types through the same pointer).
*/
- T_TriggerData = 900, /* in commands/trigger.h */
+ T_TriggerData = 950, /* in commands/trigger.h */
T_ReturnSetInfo, /* in nodes/execnodes.h */
T_TIDBitmap /* in nodes/tidbitmap.h */
} NodeTag;
@@ -430,10 +435,9 @@ typedef double Cost; /* execution cost (in page-access units) */
/*
* CmdType -
- * enums for type of operation represented by a Query
+ * enums for type of operation represented by a Query or PlannedStmt
*
- * ??? could have put this in parsenodes.h but many files not in the
- * optimizer also need this...
+ * This is needed in both parsenodes.h and plannodes.h, so put it here...
*/
typedef enum CmdType
{
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 0db7276302..ec9ccb6ce3 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.340 2007/02/03 14:06:55 petere Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.341 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,15 +27,6 @@ typedef enum QuerySource
QSRC_NON_INSTEAD_RULE /* added by non-INSTEAD rule */
} QuerySource;
-/* What to do at commit time for temporary relations */
-typedef enum OnCommitAction
-{
- ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
- ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
- ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
- ONCOMMIT_DROP /* ON COMMIT DROP */
-} OnCommitAction;
-
/* Sort ordering options for ORDER BY and CREATE INDEX */
typedef enum SortByDir
{
@@ -86,11 +77,14 @@ typedef uint32 AclMode; /* a bitmask of privilege bits */
/*
* Query -
- * all statements are turned into a Query tree (via transformStmt)
- * for further processing by the optimizer
+ * Parse analysis turns all statements into a Query tree (via transformStmt)
+ * for further processing by the rewriter and planner.
*
- * utility statements (i.e. non-optimizable statements) have the
+ * Utility statements (i.e. non-optimizable statements) have the
* utilityStmt field set, and the Query itself is mostly dummy.
+ *
+ * Planning converts a Query tree into a Plan tree headed by a PlannedStmt
+ * noded --- the Query structure is not used by the executor.
*/
typedef struct Query
{
@@ -108,10 +102,7 @@ typedef struct Query
int resultRelation; /* rtable index of target relation for
* INSERT/UPDATE/DELETE; 0 for SELECT */
- RangeVar *into; /* target relation for SELECT INTO */
- List *intoOptions; /* options from WITH clause */
- OnCommitAction intoOnCommit; /* what do we do at COMMIT? */
- char *intoTableSpaceName; /* table space to use, or NULL */
+ IntoClause *into; /* target for SELECT INTO / CREATE TABLE AS */
bool hasAggs; /* has aggregates in tlist or havingQual */
bool hasSubLinks; /* has subquery SubLink */
@@ -138,29 +129,6 @@ typedef struct Query
Node *setOperations; /* set-operation tree if this is top level of
* a UNION/INTERSECT/EXCEPT query */
-
- /*
- * If the resultRelation turns out to be the parent of an inheritance
- * tree, the planner will add all the child tables to the rtable and store
- * a list of the rtindexes of all the result relations here. This is done
- * at plan time, not parse time, since we don't want to commit to the
- * exact set of child tables at parse time. XXX This field ought to go in
- * some sort of TopPlan plan node, not in the Query.
- */
- List *resultRelations; /* integer list of RT indexes, or NIL */
-
- /*
- * If the query has a returningList then the planner will store a list of
- * processed targetlists (one per result relation) here. We must have a
- * separate RETURNING targetlist for each result rel because column
- * numbers may vary within an inheritance tree. In the targetlists, Vars
- * referencing the result relation will have their original varno and
- * varattno, while Vars referencing other rels will be converted to have
- * varno OUTER and varattno referencing a resjunk entry in the top plan
- * node's targetlist. XXX This field ought to go in some sort of TopPlan
- * plan node, not in the Query.
- */
- List *returningLists; /* list of lists of TargetEntry, or NIL */
} Query;
@@ -761,17 +729,10 @@ typedef struct SelectStmt
/*
* These fields are used only in "leaf" SelectStmts.
- *
- * into, intoColNames, intoOptions, intoOnCommit, and intoTableSpaceName
- * are a kluge; they belong somewhere else...
*/
List *distinctClause; /* NULL, list of DISTINCT ON exprs, or
* lcons(NIL,NIL) for all (SELECT DISTINCT) */
- RangeVar *into; /* target table (for select into table) */
- List *intoColNames; /* column names for into table */
- List *intoOptions; /* options from WITH clause */
- OnCommitAction intoOnCommit; /* what do we do at COMMIT? */
- char *intoTableSpaceName; /* table space to use, or NULL */
+ IntoClause *into; /* target for SELECT INTO / CREATE TABLE AS */
List *targetList; /* the target list (of ResTarget) */
List *fromClause; /* the FROM clause */
Node *whereClause; /* WHERE qualification */
@@ -1994,10 +1955,7 @@ typedef struct ExecuteStmt
{
NodeTag type;
char *name; /* The name of the plan to execute */
- RangeVar *into; /* Optional table to store results in */
- List *intoOptions; /* Options from WITH clause */
- OnCommitAction into_on_commit; /* What do we do at COMMIT? */
- char *into_tbl_space; /* Tablespace to use, or NULL */
+ IntoClause *into; /* Optional table to store results in */
List *params; /* Values to assign to parameters */
} ExecuteStmt;
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index cdd7b4d2e4..537981462b 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.90 2007/02/19 02:23:12 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.91 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -25,6 +25,48 @@
*/
/* ----------------
+ * PlannedStmt node
+ *
+ * The output of the planner is a Plan tree headed by a PlannedStmt node.
+ * PlannedStmt holds the "one time" information needed by the executor.
+ * ----------------
+ */
+typedef struct PlannedStmt
+{
+ NodeTag type;
+
+ CmdType commandType; /* select|insert|update|delete */
+
+ bool canSetTag; /* do I set the command result tag? */
+
+ struct Plan *planTree; /* tree of Plan nodes */
+
+ List *rtable; /* list of RangeTblEntry nodes */
+
+ /* rtable indexes of target relations for INSERT/UPDATE/DELETE */
+ List *resultRelations; /* integer list of RT indexes, or NIL */
+
+ IntoClause *into; /* target for SELECT INTO / CREATE TABLE AS */
+
+ /*
+ * If the query has a returningList then the planner will store a list of
+ * processed targetlists (one per result relation) here. We must have a
+ * separate RETURNING targetlist for each result rel because column
+ * numbers may vary within an inheritance tree. In the targetlists, Vars
+ * referencing the result relation will have their original varno and
+ * varattno, while Vars referencing other rels will be converted to have
+ * varno OUTER and varattno referencing a resjunk entry in the top plan
+ * node's targetlist.
+ */
+ List *returningLists; /* list of lists of TargetEntry, or NIL */
+
+ List *rowMarks; /* a list of RowMarkClause's */
+
+ int nParamExec; /* number of PARAM_EXEC Params used */
+} PlannedStmt;
+
+
+/* ----------------
* Plan node
*
* All plan nodes "derive" from the Plan structure by having the
@@ -75,15 +117,6 @@ typedef struct Plan
*/
Bitmapset *extParam;
Bitmapset *allParam;
-
- /*
- * We really need in some TopPlan node to store range table and
- * resultRelation from Query there and get rid of Query itself from
- * Executor. Some other stuff like below could be put there, too.
- */
- int nParamExec; /* Number of them in entire query. This is to
- * get Executor know about how many PARAM_EXEC
- * there are in query plan. */
} Plan;
/* ----------------
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index caa689e262..185673f729 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.125 2007/02/19 07:03:31 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.126 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -49,6 +49,15 @@ typedef enum InhOption
INH_DEFAULT /* Use current SQL_inheritance option */
} InhOption;
+/* What to do at commit time for temporary relations */
+typedef enum OnCommitAction
+{
+ ONCOMMIT_NOOP, /* No ON COMMIT clause (do nothing) */
+ ONCOMMIT_PRESERVE_ROWS, /* ON COMMIT PRESERVE ROWS (do nothing) */
+ ONCOMMIT_DELETE_ROWS, /* ON COMMIT DELETE ROWS */
+ ONCOMMIT_DROP /* ON COMMIT DROP */
+} OnCommitAction;
+
/*
* RangeVar - range variable, used in FROM clauses
*
@@ -69,6 +78,20 @@ typedef struct RangeVar
Alias *alias; /* table alias & optional column aliases */
} RangeVar;
+/*
+ * IntoClause - target information for SELECT INTO and CREATE TABLE AS
+ */
+typedef struct IntoClause
+{
+ NodeTag type;
+
+ RangeVar *rel; /* target relation name */
+ List *colNames; /* column names to assign, or NIL */
+ List *options; /* options from WITH clause */
+ OnCommitAction onCommit; /* what do we do at COMMIT? */
+ char *tableSpaceName; /* table space to use, or NULL */
+} IntoClause;
+
/* ----------------------------------------------------------------
* node types for executable expressions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 6de06ebc91..59ec830f3f 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.136 2007/02/19 07:03:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.137 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -110,6 +110,10 @@ typedef struct PlannerInfo
List *join_rel_list; /* list of join-relation RelOptInfos */
struct HTAB *join_rel_hash; /* optional hashtable for join relations */
+ List *resultRelations; /* integer list of RT indexes, or NIL */
+
+ List *returningLists; /* list of lists of TargetEntry, or NIL */
+
List *init_plans; /* init subplans for query */
List *eq_classes; /* list of active EquivalenceClasses */
diff --git a/src/include/optimizer/planner.h b/src/include/optimizer/planner.h
index 44d0360269..c243cdbc35 100644
--- a/src/include/optimizer/planner.h
+++ b/src/include/optimizer/planner.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/planner.h,v 1.37 2007/02/19 07:03:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/planner.h,v 1.38 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,10 +18,10 @@
#include "nodes/relation.h"
-extern Plan *planner(Query *parse, bool isCursor, int cursorOptions,
+extern PlannedStmt *planner(Query *parse, bool isCursor, int cursorOptions,
ParamListInfo boundParams);
extern Plan *subquery_planner(PlannerGlobal *glob, Query *parse,
Index level, double tuple_fraction,
- List **subquery_pathkeys);
+ PlannerInfo **subroot);
#endif /* PLANNER_H */
diff --git a/src/include/tcop/pquery.h b/src/include/tcop/pquery.h
index 3531353027..5cab498c13 100644
--- a/src/include/tcop/pquery.h
+++ b/src/include/tcop/pquery.h
@@ -7,23 +7,26 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/tcop/pquery.h,v 1.40 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/tcop/pquery.h,v 1.41 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PQUERY_H
#define PQUERY_H
+#include "nodes/parsenodes.h"
#include "utils/portal.h"
extern DLLIMPORT Portal ActivePortal;
-extern PortalStrategy ChoosePortalStrategy(List *parseTrees);
+extern PortalStrategy ChoosePortalStrategy(List *stmts);
extern List *FetchPortalTargetList(Portal portal);
+extern List *FetchStatementTargetList(Node *stmt);
+
extern void PortalStart(Portal portal, ParamListInfo params,
Snapshot snapshot);
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index ad66a61dac..2a55125576 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.86 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.87 2007/02/20 17:32:17 tgl Exp $
*
* OLD COMMENTS
* This file was created so that other c files could get the two
@@ -20,6 +20,7 @@
#define TCOPPROT_H
#include "executor/execdesc.h"
+#include "nodes/parsenodes.h"
#include "utils/guc.h"
@@ -50,7 +51,7 @@ extern List *pg_parse_and_rewrite(const char *query_string,
extern List *pg_parse_query(const char *query_string);
extern List *pg_analyze_and_rewrite(Node *parsetree, const char *query_string,
Oid *paramTypes, int numParams);
-extern Plan *pg_plan_query(Query *querytree, ParamListInfo boundParams);
+extern PlannedStmt *pg_plan_query(Query *querytree, ParamListInfo boundParams);
extern List *pg_plan_queries(List *querytrees, ParamListInfo boundParams,
bool needSnapshot);
diff --git a/src/include/tcop/utility.h b/src/include/tcop/utility.h
index ebcaf59772..52c0225306 100644
--- a/src/include/tcop/utility.h
+++ b/src/include/tcop/utility.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.30 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.31 2007/02/20 17:32:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,15 +26,9 @@ extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
extern const char *CreateCommandTag(Node *parsetree);
-extern const char *CreateQueryTag(Query *parsetree);
-
extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
-extern LogStmtLevel GetQueryLogLevel(Query *parsetree);
-
-extern bool QueryReturnsTuples(Query *parsetree);
-
-extern bool QueryIsReadOnly(Query *parsetree);
+extern bool CommandIsReadOnly(Node *parsetree);
extern void CheckRelationOwnership(RangeVar *rel, bool noCatalogs);
diff --git a/src/include/utils/portal.h b/src/include/utils/portal.h
index 5eb2c715e3..aa432abb87 100644
--- a/src/include/utils/portal.h
+++ b/src/include/utils/portal.h
@@ -12,7 +12,7 @@
* to let the client suspend an update-type query partway through! Because
* the query rewriter does not allow arbitrary ON SELECT rewrite rules,
* only queries that were originally update-type could produce multiple
- * parse/plan trees; so the restriction to a single query is not a problem
+ * plan trees; so the restriction to a single query is not a problem
* in practice.
*
* For SQL cursors, we support three kinds of scroll behavior:
@@ -39,7 +39,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.72 2007/01/05 22:19:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.73 2007/02/20 17:32:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -124,9 +124,8 @@ typedef struct PortalData
/* The query or queries the portal will execute */
const char *sourceText; /* text of query, if known (may be NULL) */
const char *commandTag; /* command tag for original query */
- List *parseTrees; /* parse tree(s) */
- List *planTrees; /* plan tree(s) */
- MemoryContext queryContext; /* where the parse trees live */
+ List *stmts; /* PlannedStmts and/or utility statements */
+ MemoryContext queryContext; /* where the plan trees live */
/*
* Note: queryContext effectively identifies which prepared statement the
@@ -191,7 +190,7 @@ typedef struct PortalData
*/
#define PortalGetQueryDesc(portal) ((portal)->queryDesc)
#define PortalGetHeapMemory(portal) ((portal)->heap)
-#define PortalGetPrimaryQuery(portal) PortalListGetPrimaryQuery((portal)->parseTrees)
+#define PortalGetPrimaryStmt(portal) PortalListGetPrimaryStmt((portal)->stmts)
/* Prototypes for functions in utils/mmgr/portalmem.c */
@@ -217,10 +216,9 @@ extern void PortalDefineQuery(Portal portal,
const char *prepStmtName,
const char *sourceText,
const char *commandTag,
- List *parseTrees,
- List *planTrees,
+ List *stmts,
MemoryContext queryContext);
-extern Query *PortalListGetPrimaryQuery(List *parseTrees);
+extern Node *PortalListGetPrimaryStmt(List *stmts);
extern void PortalCreateHoldStore(Portal portal);
#endif /* PORTAL_H */