summaryrefslogtreecommitdiff
path: root/src/include/nodes
diff options
context:
space:
mode:
authorGreg Stark2013-07-29 15:38:01 +0000
committerGreg Stark2013-07-29 15:38:01 +0000
commitc62736cc37f6812d1ebb41ea5a86ffe60564a1f0 (patch)
tree3cb1654476a7e45620d9a3320a002495d000380e /src/include/nodes
parent55cbfa5366b78d93cd1ff8c4c622b552985344f6 (diff)
Add SQL Standard WITH ORDINALITY support for UNNEST (and any other SRF)
Author: Andrew Gierth, David Fetter Reviewers: Dean Rasheed, Jeevan Chalke, Stephen Frost
Diffstat (limited to 'src/include/nodes')
-rw-r--r--src/include/nodes/execnodes.h10
-rw-r--r--src/include/nodes/parsenodes.h22
-rw-r--r--src/include/nodes/plannodes.h1
3 files changed, 26 insertions, 7 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 298af26e96..3b430e0f24 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -1395,7 +1395,10 @@ typedef struct SubqueryScanState
* function appearing in FROM (typically a function returning set).
*
* eflags node's capability flags
- * tupdesc expected return tuple description
+ * ordinal column value for WITH ORDINALITY
+ * scan_tupdesc scan tuple descriptor
+ * func_tupdesc function tuple descriptor
+ * func_slot function result slot, or null
* tuplestorestate private state of tuplestore.c
* funcexpr state for function expression being evaluated
* ----------------
@@ -1404,7 +1407,10 @@ typedef struct FunctionScanState
{
ScanState ss; /* its first field is NodeTag */
int eflags;
- TupleDesc tupdesc;
+ int64 ordinal;
+ TupleDesc scan_tupdesc;
+ TupleDesc func_tupdesc;
+ TupleTableSlot *func_slot;
Tuplestorestate *tuplestorestate;
ExprState *funcexpr;
} FunctionScanState;
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index b4013e893d..51fef68ca3 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -471,6 +471,7 @@ typedef struct RangeFunction
{
NodeTag type;
bool lateral; /* does it have LATERAL prefix? */
+ bool ordinality; /* does it have WITH ORDINALITY suffix? */
Node *funccallnode; /* untransformed function call tree */
Alias *alias; /* table alias & optional column aliases */
List *coldeflist; /* list of ColumnDef nodes to describe result
@@ -651,8 +652,13 @@ typedef struct XmlSerialize
* dropped columns. Note however that a stored rule may have nonempty
* colnames for columns dropped since the rule was created (and for that
* matter the colnames might be out of date due to column renamings).
+ *
* The same comments apply to FUNCTION RTEs when the function's return type
- * is a named composite type.
+ * is a named composite type. In addition, for all return types, FUNCTION
+ * RTEs with ORDINALITY must always have the last colname entry being the
+ * one for the ordinal column; this is enforced when constructing the RTE.
+ * Thus when ORDINALITY is used, there will be exactly one more colname
+ * than would have been present otherwise.
*
* In JOIN RTEs, the colnames in both alias and eref are one-to-one with
* joinaliasvars entries. A JOIN RTE will omit columns of its inputs when
@@ -751,15 +757,21 @@ typedef struct RangeTblEntry
/*
* Fields valid for a function RTE (else NULL):
*
- * If the function returns RECORD, funccoltypes lists the column types
- * declared in the RTE's column type specification, funccoltypmods lists
- * their declared typmods, funccolcollations their collations. Otherwise,
- * those fields are NIL.
+ * If the function returns an otherwise-unspecified RECORD, funccoltypes
+ * lists the column types declared in the RTE's column type specification,
+ * funccoltypmods lists their declared typmods, funccolcollations their
+ * collations. Note that in this case, ORDINALITY is not permitted, so
+ * there is no extra ordinal column to be allowed for.
+ *
+ * Otherwise, those fields are NIL, and the result column types must be
+ * derived from the funcexpr while treating the ordinal column, if
+ * present, as a special case. (see get_rte_attribute_*)
*/
Node *funcexpr; /* expression tree for func call */
List *funccoltypes; /* OID list of column type OIDs */
List *funccoltypmods; /* integer list of column typmods */
List *funccolcollations; /* OID list of column collation OIDs */
+ bool funcordinality; /* is this called WITH ORDINALITY? */
/*
* Fields valid for a values RTE (else NIL):
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index aa4f12cec5..44ea0b7752 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -425,6 +425,7 @@ typedef struct FunctionScan
{
Scan scan;
Node *funcexpr; /* expression tree for func call */
+ bool funcordinality; /* WITH ORDINALITY */
List *funccolnames; /* output column names (string Value nodes) */
List *funccoltypes; /* OID list of column type OIDs */
List *funccoltypmods; /* integer list of column typmods */