Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita552e3b

Browse files
committed
Fix parsetree representation of XMLTABLE(XMLNAMESPACES(DEFAULT ...)).
The original coding for XMLTABLE thought it could represent a defaultnamespace by a T_String Value node with a null string pointer. That'snot okay, though; in particular outfuncs.c/readfuncs.c are not on boardwith such a representation, meaning you'll get a null pointer crashif you try to store a view or rule containing this construct.To fix, change the parsetree representation so that we have a NULLlist element, instead of a bogus Value node.This isn't really a functional limitation since default XML namespacesaren't yet implemented in the executor; you'd just get "DEFAULTnamespace is not supported" anyway. But crashes are not nice, soback-patch to v10 where this syntax was added. Ordinarily we'd considera parsetree representation change to be un-backpatchable; but sinceexisting releases would crash on the way to storing such constructs,there can't be any existing views/rules to be incompatible with.Per report from Andrey Lepikhov.Discussion:https://postgr.es/m/3690074f-abd2-56a9-144a-aa5545d7a291@postgrespro.ru
1 parent3ea7e01 commita552e3b

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

‎src/backend/executor/nodeTableFuncscan.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
370370
forboth(lc1,tstate->ns_uris,lc2,tstate->ns_names)
371371
{
372372
ExprState*expr= (ExprState*)lfirst(lc1);
373-
char*ns_name=strVal(lfirst(lc2));
373+
Value*ns_node=(Value*)lfirst(lc2);
374374
char*ns_uri;
375+
char*ns_name;
375376

376377
value=ExecEvalExpr((ExprState*)expr,econtext,&isnull);
377378
if (isnull)
@@ -380,6 +381,9 @@ tfuncInitialize(TableFuncScanState *tstate, ExprContext *econtext, Datum doc)
380381
errmsg("namespace URI must not be null")));
381382
ns_uri=TextDatumGetCString(value);
382383

384+
/* DEFAULT is passed down to SetNamespace as NULL */
385+
ns_name=ns_node ?strVal(ns_node) :NULL;
386+
383387
routine->SetNamespace(tstate,ns_name,ns_uri);
384388
}
385389

‎src/backend/parser/parse_clause.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
772772
/* undef ordinality column number */
773773
tf->ordinalitycol=-1;
774774

775-
775+
/* Process column specs */
776776
names=palloc(sizeof(char*)*list_length(rtf->columns));
777777

778778
colno=0;
@@ -893,15 +893,15 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
893893
{
894894
foreach(lc2,ns_names)
895895
{
896-
char*name=strVal(lfirst(lc2));
896+
Value*ns_node=(Value*)lfirst(lc2);
897897

898-
if (name==NULL)
898+
if (ns_node==NULL)
899899
continue;
900-
if (strcmp(name,r->name)==0)
900+
if (strcmp(strVal(ns_node),r->name)==0)
901901
ereport(ERROR,
902902
(errcode(ERRCODE_SYNTAX_ERROR),
903903
errmsg("namespace name \"%s\" is not unique",
904-
name),
904+
r->name),
905905
parser_errposition(pstate,r->location)));
906906
}
907907
}
@@ -915,8 +915,9 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
915915
default_ns_seen= true;
916916
}
917917

918-
/* Note the string may be NULL */
919-
ns_names=lappend(ns_names,makeString(r->name));
918+
/* We represent DEFAULT by a null pointer */
919+
ns_names=lappend(ns_names,
920+
r->name ?makeString(r->name) :NULL);
920921
}
921922

922923
tf->ns_uris=ns_uris;

‎src/backend/utils/adt/ruleutils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9618,17 +9618,17 @@ get_tablefunc(TableFunc *tf, deparse_context *context, bool showimplicit)
96189618
forboth(lc1,tf->ns_uris,lc2,tf->ns_names)
96199619
{
96209620
Node*expr= (Node*)lfirst(lc1);
9621-
char*name=strVal(lfirst(lc2));
9621+
Value*ns_node=(Value*)lfirst(lc2);
96229622

96239623
if (!first)
96249624
appendStringInfoString(buf,", ");
96259625
else
96269626
first= false;
96279627

9628-
if (name!=NULL)
9628+
if (ns_node!=NULL)
96299629
{
96309630
get_rule_expr(expr,context,showimplicit);
9631-
appendStringInfo(buf," AS %s",name);
9631+
appendStringInfo(buf," AS %s",strVal(ns_node));
96329632
}
96339633
else
96349634
{

‎src/include/nodes/execnodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,8 @@ typedef struct TableFuncScanState
14761476
ExprState*rowexpr;/* state for row-generating expression */
14771477
List*colexprs;/* state for column-generating expression */
14781478
List*coldefexprs;/* state for column default expressions */
1479-
List*ns_names;/*list of str nodes with namespace names */
1480-
List*ns_uris;/* list of states of namespaceuri exprs */
1479+
List*ns_names;/*same as TableFunc.ns_names */
1480+
List*ns_uris;/* list of states of namespaceURI exprs */
14811481
Bitmapset*notnulls;/* nullability flag for each output column */
14821482
void*opaque;/* table builder private space */
14831483
conststructTableFuncRoutine*routine;/* table builder methods */

‎src/include/nodes/primnodes.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ typedef struct RangeVar
7575

7676
/*
7777
* TableFunc - node for a table function, such as XMLTABLE.
78+
*
79+
* Entries in the ns_names list are either string Value nodes containing
80+
* literal namespace names, or NULL pointers to represent DEFAULT.
7881
*/
7982
typedefstructTableFunc
8083
{
8184
NodeTagtype;
82-
List*ns_uris;/* list of namespaceuri */
83-
List*ns_names;/* list of namespace names */
85+
List*ns_uris;/* list of namespaceURI expressions */
86+
List*ns_names;/* list of namespace namesor NULL*/
8487
Node*docexpr;/* input document expression */
8588
Node*rowexpr;/* row filter expression */
8689
List*colnames;/* column names (list of String) */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp