mirror of
https://github.com/postgres/postgres.git
synced 2025-07-18 17:42:25 +03:00
Support XMLTABLE query expression
XMLTABLE is defined by the SQL/XML standard as a feature that allows turning XML-formatted data into relational form, so that it can be used as a <table primary> in the FROM clause of a query. This new construct provides significant simplicity and performance benefit for XML data processing; what in a client-side custom implementation was reported to take 20 minutes can be executed in 400ms using XMLTABLE. (The same functionality was said to take 10 seconds using nested PostgreSQL XPath function calls, and 5 seconds using XMLReader under PL/Python). The implemented syntax deviates slightly from what the standard requires. First, the standard indicates that the PASSING clause is optional and that multiple XML input documents may be given to it; we make it mandatory and accept a single document only. Second, we don't currently support a default namespace to be specified. This implementation relies on a new executor node based on a hardcoded method table. (Because the grammar is fixed, there is no extensibility in the current approach; further constructs can be implemented on top of this such as JSON_TABLE, but they require changes to core code.) Author: Pavel Stehule, Álvaro Herrera Extensively reviewed by: Craig Ringer Discussion: https://postgr.es/m/CAFj8pRAgfzMD-LoSmnMGybD0WsEznLHWap8DO79+-GTRAPR4qA@mail.gmail.com
This commit is contained in:
@ -565,6 +565,16 @@ _outFunctionScan(StringInfo str, const FunctionScan *node)
|
||||
WRITE_BOOL_FIELD(funcordinality);
|
||||
}
|
||||
|
||||
static void
|
||||
_outTableFuncScan(StringInfo str, const TableFuncScan *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("TABLEFUNCSCAN");
|
||||
|
||||
_outScanInfo(str, (const Scan *) node);
|
||||
|
||||
WRITE_NODE_FIELD(tablefunc);
|
||||
}
|
||||
|
||||
static void
|
||||
_outValuesScan(StringInfo str, const ValuesScan *node)
|
||||
{
|
||||
@ -955,6 +965,26 @@ _outRangeVar(StringInfo str, const RangeVar *node)
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outTableFunc(StringInfo str, const TableFunc *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("TABLEFUNC");
|
||||
|
||||
WRITE_NODE_FIELD(ns_names);
|
||||
WRITE_NODE_FIELD(ns_uris);
|
||||
WRITE_NODE_FIELD(docexpr);
|
||||
WRITE_NODE_FIELD(rowexpr);
|
||||
WRITE_NODE_FIELD(colnames);
|
||||
WRITE_NODE_FIELD(coltypes);
|
||||
WRITE_NODE_FIELD(coltypmods);
|
||||
WRITE_NODE_FIELD(colcollations);
|
||||
WRITE_NODE_FIELD(colexprs);
|
||||
WRITE_NODE_FIELD(coldefexprs);
|
||||
WRITE_BITMAPSET_FIELD(notnulls);
|
||||
WRITE_INT_FIELD(ordinalitycol);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outIntoClause(StringInfo str, const IntoClause *node)
|
||||
{
|
||||
@ -2869,6 +2899,9 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
||||
WRITE_NODE_FIELD(functions);
|
||||
WRITE_BOOL_FIELD(funcordinality);
|
||||
break;
|
||||
case RTE_TABLEFUNC:
|
||||
WRITE_NODE_FIELD(tablefunc);
|
||||
break;
|
||||
case RTE_VALUES:
|
||||
WRITE_NODE_FIELD(values_lists);
|
||||
WRITE_NODE_FIELD(coltypes);
|
||||
@ -3191,6 +3224,34 @@ _outRangeTableSample(StringInfo str, const RangeTableSample *node)
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outRangeTableFunc(StringInfo str, const RangeTableFunc *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("RANGETABLEFUNC");
|
||||
|
||||
WRITE_BOOL_FIELD(lateral);
|
||||
WRITE_NODE_FIELD(docexpr);
|
||||
WRITE_NODE_FIELD(rowexpr);
|
||||
WRITE_NODE_FIELD(namespaces);
|
||||
WRITE_NODE_FIELD(columns);
|
||||
WRITE_NODE_FIELD(alias);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outRangeTableFuncCol(StringInfo str, const RangeTableFuncCol *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("RANGETABLEFUNCCOL");
|
||||
|
||||
WRITE_STRING_FIELD(colname);
|
||||
WRITE_NODE_FIELD(typeName);
|
||||
WRITE_BOOL_FIELD(for_ordinality);
|
||||
WRITE_BOOL_FIELD(is_not_null);
|
||||
WRITE_NODE_FIELD(colexpr);
|
||||
WRITE_NODE_FIELD(coldefexpr);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
static void
|
||||
_outConstraint(StringInfo str, const Constraint *node)
|
||||
{
|
||||
@ -3440,6 +3501,9 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_FunctionScan:
|
||||
_outFunctionScan(str, obj);
|
||||
break;
|
||||
case T_TableFuncScan:
|
||||
_outTableFuncScan(str, obj);
|
||||
break;
|
||||
case T_ValuesScan:
|
||||
_outValuesScan(str, obj);
|
||||
break;
|
||||
@ -3512,6 +3576,9 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_RangeVar:
|
||||
_outRangeVar(str, obj);
|
||||
break;
|
||||
case T_TableFunc:
|
||||
_outTableFunc(str, obj);
|
||||
break;
|
||||
case T_IntoClause:
|
||||
_outIntoClause(str, obj);
|
||||
break;
|
||||
@ -3922,6 +3989,12 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_RangeTableSample:
|
||||
_outRangeTableSample(str, obj);
|
||||
break;
|
||||
case T_RangeTableFunc:
|
||||
_outRangeTableFunc(str, obj);
|
||||
break;
|
||||
case T_RangeTableFuncCol:
|
||||
_outRangeTableFuncCol(str, obj);
|
||||
break;
|
||||
case T_Constraint:
|
||||
_outConstraint(str, obj);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user