summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/catversion.h2
-rw-r--r--src/include/executor/nodeTableFuncscan.h24
-rw-r--r--src/include/executor/tablefunc.h67
-rw-r--r--src/include/nodes/execnodes.h25
-rw-r--r--src/include/nodes/nodes.h5
-rw-r--r--src/include/nodes/parsenodes.h39
-rw-r--r--src/include/nodes/plannodes.h10
-rw-r--r--src/include/nodes/primnodes.h22
-rw-r--r--src/include/optimizer/cost.h5
-rw-r--r--src/include/optimizer/pathnode.h4
-rw-r--r--src/include/parser/kwlist.h3
-rw-r--r--src/include/parser/parse_coerce.h4
-rw-r--r--src/include/parser/parse_relation.h5
-rw-r--r--src/include/utils/xml.h3
14 files changed, 217 insertions, 1 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 8d98195576..4c05b30068 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201703061
+#define CATALOG_VERSION_NO 201703081
#endif
diff --git a/src/include/executor/nodeTableFuncscan.h b/src/include/executor/nodeTableFuncscan.h
new file mode 100644
index 0000000000..529c929993
--- /dev/null
+++ b/src/include/executor/nodeTableFuncscan.h
@@ -0,0 +1,24 @@
+/*-------------------------------------------------------------------------
+ *
+ * nodeTableFuncscan.h
+ *
+ *
+ *
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/executor/nodeTableFuncscan.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef NODETABLEFUNCSCAN_H
+#define NODETABLEFUNCSCAN_H
+
+#include "nodes/execnodes.h"
+
+extern TableFuncScanState *ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags);
+extern TupleTableSlot *ExecTableFuncScan(TableFuncScanState *node);
+extern void ExecEndTableFuncScan(TableFuncScanState *node);
+extern void ExecReScanTableFuncScan(TableFuncScanState *node);
+
+#endif /* NODETABLEFUNCSCAN_H */
diff --git a/src/include/executor/tablefunc.h b/src/include/executor/tablefunc.h
new file mode 100644
index 0000000000..89d6381220
--- /dev/null
+++ b/src/include/executor/tablefunc.h
@@ -0,0 +1,67 @@
+/*-------------------------------------------------------------------------
+ *
+ * tablefunc.h
+ * interface for TableFunc executor node
+ *
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/executor/tablefunc.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef _TABLEFUNC_H
+#define _TABLEFUNC_H
+
+/* Forward-declare this to avoid including execnodes.h here */
+struct TableFuncScanState;
+
+/*
+ * TableFuncRoutine holds function pointers used for generating content of
+ * table-producer functions, such as XMLTABLE.
+ *
+ * InitBuilder initialize table builder private objects. The output tuple
+ * descriptor, input functions for the columns, and typioparams are passed
+ * from executor state.
+ *
+ * SetDoc is called to define the input document. The table builder may
+ * apply additional transformations not exposed outside the table builder
+ * context.
+ *
+ * SetNamespace is called to pass namespace declarations from the table
+ * expression. This function may be NULL if namespaces are not supported by
+ * the table builder. Namespaces must be given before setting the row and
+ * column filters. If the name is given as NULL, the entry shall be for the
+ * default namespace.
+ *
+ * SetRowFilter is called do define the row-generating filter, which shall be
+ * used to extract each row from the input document.
+ *
+ * SetColumnFilter is called once for each column, to define the column-
+ * generating filter for the given column.
+ *
+ * FetchRow shall be called repeatedly until it returns that no more rows are
+ * found in the document. On each invocation it shall set state in the table
+ * builder context such that each subsequent GetValue call returns the values
+ * for the indicated column for the row being processed.
+ *
+ * DestroyBuilder shall release all resources associated with a table builder
+ * context. It may be called either because all rows have been consumed, or
+ * because an error ocurred while processing the table expression.
+ */
+typedef struct TableFuncRoutine
+{
+ void (*InitOpaque) (struct TableFuncScanState *state, int natts);
+ void (*SetDocument) (struct TableFuncScanState *state, Datum value);
+ void (*SetNamespace) (struct TableFuncScanState *state, char *name,
+ char *uri);
+ void (*SetRowFilter) (struct TableFuncScanState *state, char *path);
+ void (*SetColumnFilter) (struct TableFuncScanState *state,
+ char *path, int colnum);
+ bool (*FetchRow) (struct TableFuncScanState *state);
+ Datum (*GetValue) (struct TableFuncScanState *state, int colnum,
+ Oid typid, int32 typmod, bool *isnull);
+ void (*DestroyOpaque) (struct TableFuncScanState *state);
+} TableFuncRoutine;
+
+#endif /* _TABLEFUNC_H */
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 6332ea0620..2fde67a9c8 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -1585,6 +1585,31 @@ typedef struct ValuesScanState
} ValuesScanState;
/* ----------------
+ * TableFuncScanState node
+ *
+ * Used in table-expression functions like XMLTABLE.
+ * ----------------
+ */
+typedef struct TableFuncScanState
+{
+ ScanState ss; /* its first field is NodeTag */
+ ExprState *docexpr; /* state for document expression */
+ ExprState *rowexpr; /* state for row-generating expression */
+ List *colexprs; /* state for column-generating expression */
+ List *coldefexprs; /* state for column default expressions */
+ List *ns_names; /* list of str nodes with namespace names */
+ List *ns_uris; /* list of states of namespace uri exprs */
+ Bitmapset *notnulls; /* nullability flag for each output column */
+ void *opaque; /* table builder private space */
+ const struct TableFuncRoutine *routine; /* table builder methods */
+ FmgrInfo *in_functions; /* input function for each column */
+ Oid *typioparams; /* typioparam for each column */
+ int64 ordinal; /* row number to be output next */
+ MemoryContext perValueCxt; /* short life context for value evaluation */
+ Tuplestorestate *tupstore; /* output tuple store */
+} TableFuncScanState;
+
+/* ----------------
* CteScanState information
*
* CteScan nodes are used to scan a CommonTableExpr query.
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index ede7ace76b..49fa944755 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -61,6 +61,7 @@ typedef enum NodeTag
T_SubqueryScan,
T_FunctionScan,
T_ValuesScan,
+ T_TableFuncScan,
T_CteScan,
T_WorkTableScan,
T_ForeignScan,
@@ -109,6 +110,7 @@ typedef enum NodeTag
T_TidScanState,
T_SubqueryScanState,
T_FunctionScanState,
+ T_TableFuncScanState,
T_ValuesScanState,
T_CteScanState,
T_WorkTableScanState,
@@ -135,6 +137,7 @@ typedef enum NodeTag
*/
T_Alias,
T_RangeVar,
+ T_TableFunc,
T_Expr,
T_Var,
T_Const,
@@ -439,6 +442,8 @@ typedef enum NodeTag
T_RangeSubselect,
T_RangeFunction,
T_RangeTableSample,
+ T_RangeTableFunc,
+ T_RangeTableFuncCol,
T_TypeName,
T_ColumnDef,
T_IndexElem,
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 956f99830c..a44d2178e1 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -555,6 +555,39 @@ typedef struct RangeFunction
} RangeFunction;
/*
+ * RangeTableFunc - raw form of "table functions" such as XMLTABLE
+ */
+typedef struct RangeTableFunc
+{
+ NodeTag type;
+ bool lateral; /* does it have LATERAL prefix? */
+ Node *docexpr; /* document expression */
+ Node *rowexpr; /* row generator expression */
+ List *namespaces; /* list of namespaces as ResTarget */
+ List *columns; /* list of RangeTableFuncCol */
+ Alias *alias; /* table alias & optional column aliases */
+ int location; /* token location, or -1 if unknown */
+} RangeTableFunc;
+
+/*
+ * RangeTableFuncCol - one column in a RangeTableFunc->columns
+ *
+ * If for_ordinality is true (FOR ORDINALITY), then the column is an int4
+ * column and the rest of the fields are ignored.
+ */
+typedef struct RangeTableFuncCol
+{
+ NodeTag type;
+ char *colname; /* name of generated column */
+ TypeName *typeName; /* type of generated column */
+ bool for_ordinality; /* does it have FOR ORDINALITY? */
+ bool is_not_null; /* does it have NOT NULL? */
+ Node *colexpr; /* column filter expression */
+ Node *coldefexpr; /* column default value expression */
+ int location; /* token location, or -1 if unknown */
+} RangeTableFuncCol;
+
+/*
* RangeTableSample - TABLESAMPLE appearing in a raw FROM clause
*
* This node, appearing only in raw parse trees, represents
@@ -871,6 +904,7 @@ typedef enum RTEKind
RTE_SUBQUERY, /* subquery in FROM */
RTE_JOIN, /* join */
RTE_FUNCTION, /* function in FROM */
+ RTE_TABLEFUNC, /* TableFunc(.., column list) */
RTE_VALUES, /* VALUES (<exprlist>), (<exprlist>), ... */
RTE_CTE /* common table expr (WITH list element) */
} RTEKind;
@@ -932,6 +966,11 @@ typedef struct RangeTblEntry
bool funcordinality; /* is this called WITH ORDINALITY? */
/*
+ * Fields valid for a TableFunc RTE (else NULL):
+ */
+ TableFunc *tablefunc;
+
+ /*
* Fields valid for a values RTE (else NIL):
*/
List *values_lists; /* list of expression lists */
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index f72f7a8978..e30ed6aa29 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -496,6 +496,16 @@ typedef struct ValuesScan
} ValuesScan;
/* ----------------
+ * TableFunc scan node
+ * ----------------
+ */
+typedef struct TableFuncScan
+{
+ Scan scan;
+ TableFunc *tablefunc; /* table function node */
+} TableFuncScan;
+
+/* ----------------
* CteScan node
* ----------------
*/
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index 235bc75096..d57b4fab3d 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -18,6 +18,7 @@
#define PRIMNODES_H
#include "access/attnum.h"
+#include "nodes/bitmapset.h"
#include "nodes/pg_list.h"
@@ -73,6 +74,27 @@ typedef struct RangeVar
} RangeVar;
/*
+ * TableFunc - node for a table function, such as XMLTABLE.
+ */
+typedef struct TableFunc
+{
+ NodeTag type;
+ List *ns_uris; /* list of namespace uri */
+ List *ns_names; /* list of namespace names */
+ Node *docexpr; /* input document expression */
+ Node *rowexpr; /* row filter expression */
+ List *colnames; /* column names (list of String) */
+ List *coltypes; /* OID list of column type OIDs */
+ List *coltypmods; /* integer list of column typmods */
+ List *colcollations; /* OID list of column collation OIDs */
+ List *colexprs; /* list of column filter expressions */
+ List *coldefexprs; /* list of column default expressions */
+ Bitmapset *notnulls; /* nullability flag for each output column */
+ int ordinalitycol; /* counts from 0; -1 if none specified */
+ int location; /* token location, or -1 if unknown */
+} TableFunc;
+
+/*
* IntoClause - target information for SELECT INTO, CREATE TABLE AS, and
* CREATE MATERIALIZED VIEW
*
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
index 72200fa531..2b386835e3 100644
--- a/src/include/optimizer/cost.h
+++ b/src/include/optimizer/cost.h
@@ -89,8 +89,12 @@ extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info);
extern void cost_functionscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info);
+extern void cost_tableexprscan(Path *path, PlannerInfo *root,
+ RelOptInfo *baserel, ParamPathInfo *param_info);
extern void cost_valuesscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info);
+extern void cost_tablefuncscan(Path *path, PlannerInfo *root,
+ RelOptInfo *baserel, ParamPathInfo *param_info);
extern void cost_ctescan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, ParamPathInfo *param_info);
extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm);
@@ -181,6 +185,7 @@ extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel);
extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel,
double cte_rows);
+extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel);
extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel);
extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target);
extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel,
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
index 53cad247dc..befe578141 100644
--- a/src/include/optimizer/pathnode.h
+++ b/src/include/optimizer/pathnode.h
@@ -82,8 +82,12 @@ extern SubqueryScanPath *create_subqueryscan_path(PlannerInfo *root,
List *pathkeys, Relids required_outer);
extern Path *create_functionscan_path(PlannerInfo *root, RelOptInfo *rel,
List *pathkeys, Relids required_outer);
+extern Path *create_tablexprscan_path(PlannerInfo *root, RelOptInfo *rel,
+ List *pathkeys, Relids required_outer);
extern Path *create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel,
Relids required_outer);
+extern Path *create_tablefuncscan_path(PlannerInfo *root, RelOptInfo *rel,
+ Relids required_outer);
extern Path *create_ctescan_path(PlannerInfo *root, RelOptInfo *rel,
Relids required_outer);
extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel,
diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h
index 985d6505ec..28c4dab258 100644
--- a/src/include/parser/kwlist.h
+++ b/src/include/parser/kwlist.h
@@ -82,6 +82,7 @@ PG_KEYWORD("coalesce", COALESCE, COL_NAME_KEYWORD)
PG_KEYWORD("collate", COLLATE, RESERVED_KEYWORD)
PG_KEYWORD("collation", COLLATION, TYPE_FUNC_NAME_KEYWORD)
PG_KEYWORD("column", COLUMN, RESERVED_KEYWORD)
+PG_KEYWORD("columns", COLUMNS, UNRESERVED_KEYWORD)
PG_KEYWORD("comment", COMMENT, UNRESERVED_KEYWORD)
PG_KEYWORD("comments", COMMENTS, UNRESERVED_KEYWORD)
PG_KEYWORD("commit", COMMIT, UNRESERVED_KEYWORD)
@@ -446,10 +447,12 @@ PG_KEYWORD("xmlconcat", XMLCONCAT, COL_NAME_KEYWORD)
PG_KEYWORD("xmlelement", XMLELEMENT, COL_NAME_KEYWORD)
PG_KEYWORD("xmlexists", XMLEXISTS, COL_NAME_KEYWORD)
PG_KEYWORD("xmlforest", XMLFOREST, COL_NAME_KEYWORD)
+PG_KEYWORD("xmlnamespaces", XMLNAMESPACES, COL_NAME_KEYWORD)
PG_KEYWORD("xmlparse", XMLPARSE, COL_NAME_KEYWORD)
PG_KEYWORD("xmlpi", XMLPI, COL_NAME_KEYWORD)
PG_KEYWORD("xmlroot", XMLROOT, COL_NAME_KEYWORD)
PG_KEYWORD("xmlserialize", XMLSERIALIZE, COL_NAME_KEYWORD)
+PG_KEYWORD("xmltable", XMLTABLE, COL_NAME_KEYWORD)
PG_KEYWORD("year", YEAR_P, UNRESERVED_KEYWORD)
PG_KEYWORD("yes", YES_P, UNRESERVED_KEYWORD)
PG_KEYWORD("zone", ZONE, UNRESERVED_KEYWORD)
diff --git a/src/include/parser/parse_coerce.h b/src/include/parser/parse_coerce.h
index b50992cfd9..3eed81966d 100644
--- a/src/include/parser/parse_coerce.h
+++ b/src/include/parser/parse_coerce.h
@@ -58,6 +58,10 @@ extern Node *coerce_to_specific_type(ParseState *pstate, Node *node,
Oid targetTypeId,
const char *constructName);
+extern Node *coerce_to_specific_type_typmod(ParseState *pstate, Node *node,
+ Oid targetTypeId, int32 targetTypmod,
+ const char *constructName);
+
extern int parser_coercion_errposition(ParseState *pstate,
int coerce_location,
Node *input_expr);
diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h
index cfb2e5b88c..515c06cfef 100644
--- a/src/include/parser/parse_relation.h
+++ b/src/include/parser/parse_relation.h
@@ -91,6 +91,11 @@ extern RangeTblEntry *addRangeTableEntryForValues(ParseState *pstate,
Alias *alias,
bool lateral,
bool inFromCl);
+extern RangeTblEntry *addRangeTableEntryForTableFunc(ParseState *pstate,
+ TableFunc *tf,
+ Alias *alias,
+ bool lateral,
+ bool inFromCl);
extern RangeTblEntry *addRangeTableEntryForJoin(ParseState *pstate,
List *colnames,
JoinType jointype,
diff --git a/src/include/utils/xml.h b/src/include/utils/xml.h
index cc1fc390e8..e570b71c04 100644
--- a/src/include/utils/xml.h
+++ b/src/include/utils/xml.h
@@ -18,6 +18,7 @@
#include "fmgr.h"
#include "nodes/execnodes.h"
#include "nodes/primnodes.h"
+#include "executor/tablefunc.h"
typedef struct varlena xmltype;
@@ -76,4 +77,6 @@ extern int xmlbinary; /* XmlBinaryType, but int for guc enum */
extern int xmloption; /* XmlOptionType, but int for guc enum */
+extern const TableFuncRoutine XmlTableRoutine;
+
#endif /* XML_H */