diff options
author | Joe Conway <mail@joeconway.com> | 2006-08-02 01:59:48 +0000 |
---|---|---|
committer | Joe Conway <mail@joeconway.com> | 2006-08-02 01:59:48 +0000 |
commit | 9caafda579f699b43fa4c89bf13a2331ef00611e (patch) | |
tree | 330423c4be56ffaacb2d028153706f0c213c0aec /src/include | |
parent | d307c428cbb7c426e40163d234d993e644bbcc6b (diff) | |
download | postgresql-9caafda579f699b43fa4c89bf13a2331ef00611e.tar.gz postgresql-9caafda579f699b43fa4c89bf13a2331ef00611e.zip |
Add support for multi-row VALUES clauses as part of INSERT statements
(e.g. "INSERT ... VALUES (...), (...), ...") and elsewhere as allowed
by the spec. (e.g. similar to a FROM clause subselect). initdb required.
Joe Conway and Tom Lane.
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/catversion.h | 4 | ||||
-rw-r--r-- | src/include/executor/nodeValuesscan.h | 27 | ||||
-rw-r--r-- | src/include/nodes/execnodes.h | 23 | ||||
-rw-r--r-- | src/include/nodes/nodes.h | 4 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 47 | ||||
-rw-r--r-- | src/include/nodes/plannodes.h | 12 | ||||
-rw-r--r-- | src/include/optimizer/cost.h | 5 | ||||
-rw-r--r-- | src/include/optimizer/pathnode.h | 3 | ||||
-rw-r--r-- | src/include/parser/parse_relation.h | 6 | ||||
-rw-r--r-- | src/include/parser/parse_target.h | 12 |
10 files changed, 113 insertions, 30 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 23b0ac9ce4f..8d93308fceb 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.345 2006/07/31 20:09:05 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.346 2006/08/02 01:59:47 joe Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200607311 +#define CATALOG_VERSION_NO 200608011 #endif diff --git a/src/include/executor/nodeValuesscan.h b/src/include/executor/nodeValuesscan.h new file mode 100644 index 00000000000..5a952bdd322 --- /dev/null +++ b/src/include/executor/nodeValuesscan.h @@ -0,0 +1,27 @@ +/*------------------------------------------------------------------------- + * + * nodeValuesscan.h + * + * + * + * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/include/executor/nodeValuesscan.h,v 1.1 2006/08/02 01:59:47 joe Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef NODEVALUESSCAN_H +#define NODEVALUESSCAN_H + +#include "nodes/execnodes.h" + +extern int ExecCountSlotsValuesScan(ValuesScan *node); +extern ValuesScanState *ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags); +extern TupleTableSlot *ExecValuesScan(ValuesScanState *node); +extern void ExecEndValuesScan(ValuesScanState *node); +extern void ExecValuesMarkPos(ValuesScanState *node); +extern void ExecValuesRestrPos(ValuesScanState *node); +extern void ExecValuesReScan(ValuesScanState *node, ExprContext *exprCtxt); + +#endif /* NODEVALUESSCAN_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 8dec4130e28..2e981240037 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.155 2006/07/27 19:52:07 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.156 2006/08/02 01:59:47 joe Exp $ * *------------------------------------------------------------------------- */ @@ -1041,6 +1041,27 @@ typedef struct FunctionScanState ExprState *funcexpr; } FunctionScanState; +/* ---------------- + * ValuesScanState information + * + * Values nodes are used to scan the results of a + * values list appearing in FROM or INSERT + * + * exprlists array of expression lists being evaluated + * array_len size of array + * curr_idx current array index (0-based) + * marked_idx marked position (for mark/restore) + * ---------------- + */ +typedef struct ValuesScanState +{ + ScanState ss; /* its first field is NodeTag */ + List **exprlists; + int array_len; + int curr_idx; + int marked_idx; +} ValuesScanState; + /* ---------------------------------------------------------------- * Join State Information * ---------------------------------------------------------------- diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 53f3ee1d610..eb31fd2b6e7 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.186 2006/04/30 18:30:40 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.187 2006/08/02 01:59:47 joe Exp $ * *------------------------------------------------------------------------- */ @@ -54,6 +54,7 @@ typedef enum NodeTag T_TidScan, T_SubqueryScan, T_FunctionScan, + T_ValuesScan, T_Join, T_NestLoop, T_MergeJoin, @@ -85,6 +86,7 @@ typedef enum NodeTag T_TidScanState, T_SubqueryScanState, T_FunctionScanState, + T_ValuesScanState, T_JoinState, T_NestLoopState, T_MergeJoinState, diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 5c227156f06..d0fa16ff51c 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.319 2006/07/31 01:16:38 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.320 2006/08/02 01:59:47 joe Exp $ * *------------------------------------------------------------------------- */ @@ -303,13 +303,13 @@ typedef struct A_Indirection * ResTarget - * result target (used in target list of pre-transformed parse trees) * - * In a SELECT or INSERT target list, 'name' is the column label from an + * In a SELECT target list, 'name' is the column label from an * 'AS ColumnLabel' clause, or NULL if there was none, and 'val' is the * value expression itself. The 'indirection' field is not used. * - * INSERT has a second ResTarget list which is the target-column-names list. - * Here, 'val' is not used, 'name' is the name of the destination column, - * and 'indirection' stores any subscripts attached to the destination. + * INSERT uses ResTarget in its target-column-names list. Here, 'name' is + * the name of the destination column, 'indirection' stores any subscripts + * attached to the destination, and 'val' is not used. * * In an UPDATE target list, 'name' is the name of the destination column, * 'indirection' stores any subscripts attached to the destination, and @@ -517,7 +517,8 @@ typedef enum RTEKind RTE_SUBQUERY, /* subquery in FROM */ RTE_JOIN, /* join */ RTE_SPECIAL, /* special rule relation (NEW or OLD) */ - RTE_FUNCTION /* function in FROM */ + RTE_FUNCTION, /* function in FROM */ + RTE_VALUES /* VALUES (<exprlist>), (<exprlist>), ... */ } RTEKind; typedef struct RangeTblEntry @@ -554,6 +555,11 @@ typedef struct RangeTblEntry List *funccoltypmods; /* integer list of column typmods */ /* + * Fields valid for a values RTE (else NIL): + */ + List *values_lists; /* list of expression lists */ + + /* * Fields valid for a join RTE (else NULL/zero): * * joinaliasvars is a list of Vars or COALESCE expressions corresponding @@ -630,6 +636,10 @@ typedef struct RowMarkClause /* ---------------------- * Insert Statement + * + * The source expression is represented by SelectStmt for both the + * SELECT and VALUES cases. If selectStmt is NULL, then the query + * is INSERT ... DEFAULT VALUES. * ---------------------- */ typedef struct InsertStmt @@ -637,14 +647,7 @@ typedef struct InsertStmt NodeTag type; RangeVar *relation; /* relation to insert into */ List *cols; /* optional: names of the target columns */ - - /* - * An INSERT statement has *either* VALUES or SELECT, never both. If - * VALUES, a targetList is supplied (empty for DEFAULT VALUES). If SELECT, - * a complete SelectStmt (or set-operation tree) is supplied. - */ - List *targetList; /* the target list (of ResTarget) */ - Node *selectStmt; /* the source SELECT */ + Node *selectStmt; /* the source SELECT/VALUES, or NULL */ } InsertStmt; /* ---------------------- @@ -676,9 +679,9 @@ typedef struct UpdateStmt * Select Statement * * A "simple" SELECT is represented in the output of gram.y by a single - * SelectStmt node. A SELECT construct containing set operators (UNION, - * INTERSECT, EXCEPT) is represented by a tree of SelectStmt nodes, in - * which the leaf nodes are component SELECTs and the internal nodes + * SelectStmt node; so is a VALUES construct. A query containing set + * operators (UNION, INTERSECT, EXCEPT) is represented by a tree of SelectStmt + * nodes, in which the leaf nodes are component SELECTs and the internal nodes * represent UNION, INTERSECT, or EXCEPT operators. Using the same node * type for both leaf and internal nodes allows gram.y to stick ORDER BY, * LIMIT, etc, clause values into a SELECT statement without worrying @@ -717,6 +720,16 @@ typedef struct SelectStmt Node *havingClause; /* HAVING conditional-expression */ /* + * In a "leaf" node representing a VALUES list, the above fields are all + * null, and instead this field is set. Note that the elements of + * the sublists are just expressions, without ResTarget decoration. + * Also note that a list element can be DEFAULT (represented as a + * SetToDefault node), regardless of the context of the VALUES list. + * It's up to parse analysis to reject that where not valid. + */ + List *valuesLists; /* untransformed list of expression lists */ + + /* * These fields are used in both "leaf" SelectStmts and upper-level * SelectStmts. */ diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 78a472342bd..5c2de28a417 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.84 2006/07/26 19:31:51 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.85 2006/08/02 01:59:47 joe Exp $ * *------------------------------------------------------------------------- */ @@ -296,6 +296,16 @@ typedef struct FunctionScan /* no other fields needed at present */ } FunctionScan; +/* ---------------- + * ValuesScan node + * ---------------- + */ +typedef struct ValuesScan +{ + Scan scan; + /* no other fields needed at present */ +} ValuesScan; + /* * ========== * Join nodes diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h index 27928b89a53..30388571119 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.78 2006/07/26 11:35:56 petere Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.79 2006/08/02 01:59:48 joe Exp $ * *------------------------------------------------------------------------- */ @@ -70,6 +70,8 @@ extern void cost_tidscan(Path *path, PlannerInfo *root, extern void cost_subqueryscan(Path *path, RelOptInfo *baserel); extern void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel); +extern void cost_valuesscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel); extern void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width); extern void cost_material(Path *path, @@ -94,6 +96,7 @@ extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, JoinType jointype, List *restrictlist); extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel); /* * prototypes for clausesel.c diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 71426b5706a..e6005094b78 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.70 2006/07/22 15:41:56 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.71 2006/08/02 01:59:48 joe Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,7 @@ extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath); extern Path *create_subqueryscan_path(RelOptInfo *rel, List *pathkeys); extern Path *create_functionscan_path(PlannerInfo *root, RelOptInfo *rel); +extern Path *create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel); extern NestPath *create_nestloop_path(PlannerInfo *root, RelOptInfo *joinrel, diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h index 33ebad8abce..9e2df63c54a 100644 --- a/src/include/parser/parse_relation.h +++ b/src/include/parser/parse_relation.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.53 2006/03/14 22:48:22 tgl Exp $ + * $PostgreSQL: pgsql/src/include/parser/parse_relation.h,v 1.54 2006/08/02 01:59:48 joe Exp $ * *------------------------------------------------------------------------- */ @@ -59,6 +59,10 @@ extern RangeTblEntry *addRangeTableEntryForFunction(ParseState *pstate, Node *funcexpr, RangeFunction *rangefunc, bool inFromCl); +extern RangeTblEntry *addRangeTableEntryForValues(ParseState *pstate, + List *exprs, + Alias *alias, + bool inFromCl); extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate, List *colnames, JoinType jointype, diff --git a/src/include/parser/parse_target.h b/src/include/parser/parse_target.h index 6080696baa0..bbd154efe36 100644 --- a/src/include/parser/parse_target.h +++ b/src/include/parser/parse_target.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/parse_target.h,v 1.40 2006/06/26 17:24:41 tgl Exp $ + * $PostgreSQL: pgsql/src/include/parser/parse_target.h,v 1.41 2006/08/02 01:59:48 joe Exp $ * *------------------------------------------------------------------------- */ @@ -18,14 +18,16 @@ extern List *transformTargetList(ParseState *pstate, List *targetlist); +extern List *transformExpressionList(ParseState *pstate, List *exprlist); extern void markTargetListOrigins(ParseState *pstate, List *targetlist); extern TargetEntry *transformTargetEntry(ParseState *pstate, Node *node, Node *expr, char *colname, bool resjunk); -extern List *ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, - bool targetlist); -extern List *ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind, - bool targetlist); +extern Expr *transformAssignedExpr(ParseState *pstate, Expr *expr, + char *colname, + int attrno, + List *indirection, + int location); extern void updateTargetListEntry(ParseState *pstate, TargetEntry *tle, char *colname, int attrno, List *indirection, |