Skip to content

Commit bb2824a

Browse files
committed
Merge branch 'BABEL_5_X_DEV__PG_17_X' into jira-babel-5957
2 parents 97f09c3 + 6733da6 commit bb2824a

File tree

16 files changed

+108
-15
lines changed

16 files changed

+108
-15
lines changed

src/backend/catalog/heap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ heap_create_with_catalog(const char *relname,
13951395
strncpy(enr->md.name, relname, strlen(relname) + 1);
13961396
enr->md.reliddesc = relid;
13971397
enr->md.enrtype = ENR_TSQL_TEMP;
1398+
enr->md.parent_oid = InvalidOid;
13981399
register_ENR(currentQueryEnv, enr);
13991400
MemoryContextSwitchTo(oldcontext);
14001401
}

src/backend/catalog/index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ index_create(Relation heapRelation,
10141014
strncpy(enr->md.name, indexRelationName, strlen(indexRelationName) + 1);
10151015
enr->md.reliddesc = indexRelationId;
10161016
enr->md.enrtype = ENR_TSQL_TEMP;
1017+
enr->md.parent_oid = heapRelationId;
10171018
register_ENR(currentQueryEnv, enr);
10181019
MemoryContextSwitchTo(oldcontext);
10191020
}

src/backend/commands/functioncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver
23622362
Assert(IsA(fexpr, FuncExpr));
23632363

23642364
if (ExecFuncProc_AclCheck_hook)
2365-
aclresult = ExecFuncProc_AclCheck_hook(fexpr->funcid);
2365+
aclresult = ExecFuncProc_AclCheck_hook(fexpr->funcid, (Expr *)fexpr);
23662366
else
23672367
aclresult = object_aclcheck(ProcedureRelationId, fexpr->funcid, GetUserId(), ACL_EXECUTE);
23682368
if (aclresult != ACLCHECK_OK)

src/backend/executor/execExpr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ ExecInitFunc(ExprEvalStep *scratch, Expr *node, List *args, Oid funcid,
26392639

26402640
/* Check permission to call function */
26412641
if (ExecFuncProc_AclCheck_hook)
2642-
aclresult = ExecFuncProc_AclCheck_hook(funcid);
2642+
aclresult = ExecFuncProc_AclCheck_hook(funcid, node);
26432643
else
26442644
aclresult = object_aclcheck(ProcedureRelationId, funcid, GetUserId(), ACL_EXECUTE);
26452645
if (aclresult != ACLCHECK_OK)

src/backend/executor/execSRF.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ init_sexpr(Oid foid, Oid input_collation, Expr *node,
703703

704704
/* Check permission to call function */
705705
if (ExecFuncProc_AclCheck_hook)
706-
aclresult = ExecFuncProc_AclCheck_hook(foid);
706+
aclresult = ExecFuncProc_AclCheck_hook(foid, node);
707707
else
708708
aclresult = object_aclcheck(ProcedureRelationId, foid, GetUserId(), ACL_EXECUTE);
709709
if (aclresult != ACLCHECK_OK)

src/backend/executor/spi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,7 @@ SPI_register_trigger_data(TriggerData *tdata)
34303430
enr->md.enrtype = ENR_NAMED_TUPLESTORE;
34313431
enr->md.enrtuples = tuplestore_tuple_count(tdata->tg_newtable);
34323432
enr->reldata = tdata->tg_newtable;
3433+
enr->md.parent_oid = InvalidOid;
34333434
rc = SPI_register_relation(enr);
34343435
if (rc != SPI_OK_REL_REGISTER)
34353436
return rc;
@@ -3447,6 +3448,7 @@ SPI_register_trigger_data(TriggerData *tdata)
34473448
enr->md.enrtype = ENR_NAMED_TUPLESTORE;
34483449
enr->md.enrtuples = tuplestore_tuple_count(tdata->tg_oldtable);
34493450
enr->reldata = tdata->tg_oldtable;
3451+
enr->md.parent_oid = InvalidOid;
34503452
rc = SPI_register_relation(enr);
34513453
if (rc != SPI_OK_REL_REGISTER)
34523454
return rc;

src/backend/parser/analyze.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ pre_transform_setop_sort_clause_hook_type pre_transform_setop_sort_clause_hook =
9090
/* Hook to transform TSQL pivot clause in select stmt */
9191
transform_pivot_clause_hook_type transform_pivot_clause_hook = NULL;
9292

93-
/* Hook to transform TSQL unpivot clauses in select stmt */
94-
transform_unpivot_clause_hook_type transform_unpivot_clause_hook = NULL;
93+
/* Hook to transform TSQL unpivot, top N percent clauses in select stmt */
94+
transform_tsql_select_stmt_hook_type transform_tsql_select_stmt_hook = NULL;
95+
9596

9697
static Query *transformOptionalSelectInto(ParseState *pstate, Node *parseTree);
9798
static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt);
@@ -1441,10 +1442,10 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
14411442

14421443
qry->commandType = CMD_SELECT;
14431444

1444-
/* Unpack and process TSQL UNPIVOT nodes in stmt->fromClause, if present */
1445-
if(transform_unpivot_clause_hook)
1445+
/* Unpack and process TSQL UNPIVOT nodes in stmt->fromClause, Process Top N Percent, if present */
1446+
if(transform_tsql_select_stmt_hook)
14461447
{
1447-
(*transform_unpivot_clause_hook)(pstate, stmt);
1448+
(*transform_tsql_select_stmt_hook)(pstate, stmt);
14481449
}
14491450

14501451
/* process the WITH clause independently of all else */

src/backend/parser/parse_clause.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ sortby_nulls_hook_type sortby_nulls_hook = NULL;
5656

5757
optimize_explicit_cast_hook_type optimize_explicit_cast_hook = NULL;
5858

59+
pre_transform_openxml_columns_hook_type pre_transform_openxml_columns_hook = NULL;
60+
5961
static int extractRemainingColumns(ParseState *pstate,
6062
ParseNamespaceColumn *src_nscolumns,
6163
List *src_colnames,
@@ -711,6 +713,13 @@ transformRangeTableFunc(ParseState *pstate, RangeTableFunc *rtf)
711713
constructName = "XMLTABLE";
712714
docType = XMLOID;
713715

716+
/*
717+
* Hook to allow extensions to pre-process OPENXML column definitions
718+
* before standard XMLTABLE transformation.
719+
*/
720+
if (pre_transform_openxml_columns_hook && tf->functype == TFT_XMLTABLE)
721+
pre_transform_openxml_columns_hook(pstate, rtf);
722+
714723
/*
715724
* We make lateral_only names of this level visible, whether or not the
716725
* RangeTableFunc is explicitly marked LATERAL. This is needed for SQL

src/backend/utils/adt/xml.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ const TableFuncRoutine XmlTableRoutine =
232232
.DestroyOpaque = XmlTableDestroyOpaque
233233
};
234234

235+
#ifdef USE_LIBXML
236+
openxml_set_namespaces_hook_type openxml_set_namespaces_hook = NULL;
237+
#endif
238+
235239
#define NO_XML_SUPPORT() \
236240
ereport(ERROR, \
237241
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
@@ -4797,6 +4801,10 @@ XmlTableSetNamespace(TableFuncScanState *state, const char *name, const char *ur
47974801
errmsg("DEFAULT namespace is not supported")));
47984802
xtCxt = GetXmlTableBuilderPrivateData(state, "XmlTableSetNamespace");
47994803

4804+
/* For TSQL OPENXML, following hook will fetch and register namespaces in Xpath context. */
4805+
if (openxml_set_namespaces_hook)
4806+
return openxml_set_namespaces_hook(xtCxt->xpathcxt, xtCxt->xmlerrcxt, uri);
4807+
48004808
if (xmlXPathRegisterNs(xtCxt->xpathcxt,
48014809
pg_xmlCharStrndup(name, strlen(name)),
48024810
pg_xmlCharStrndup(uri, strlen(uri))))
@@ -5116,3 +5124,28 @@ XmlTableDestroyOpaque(TableFuncScanState *state)
51165124
NO_XML_SUPPORT();
51175125
#endif /* not USE_LIBXML */
51185126
}
5127+
5128+
#ifdef USE_LIBXML
5129+
xmlDocPtr
5130+
xml_parse_wrapper(text *data, XmlOptionType xmloption_arg,
5131+
bool preserve_whitespace, int encoding,
5132+
XmlOptionType *parsed_xmloptiontype, xmlNodePtr *parsed_nodes,
5133+
Node *escontext)
5134+
{
5135+
return xml_parse(data, xmloption_arg, preserve_whitespace,
5136+
encoding, parsed_xmloptiontype, parsed_nodes, escontext);
5137+
}
5138+
5139+
xmlChar *
5140+
pg_xmlCharStrndup_wrapper(const char *str, size_t len)
5141+
{
5142+
return pg_xmlCharStrndup(str, len);
5143+
}
5144+
5145+
int
5146+
parse_xml_decl_wrapper(const xmlChar *str, size_t *lenp,
5147+
xmlChar **version, xmlChar **encoding, int *standalone)
5148+
{
5149+
return parse_xml_decl(str, lenp, version, encoding, standalone);
5150+
}
5151+
#endif /* USE_LIBXML */

src/backend/utils/misc/queryenvironment.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,30 @@ register_ENR(QueryEnvironment *queryEnv, EphemeralNamedRelation enr)
212212
Assert(enr != NULL);
213213
Assert(get_ENR(queryEnv, enr->md.name, false) == NULL);
214214

215-
if (enr->md.name[0] == '#')
216-
enr->md.is_bbf_temp_table = true;
217-
else
218-
enr->md.is_bbf_temp_table = false;
215+
if (enr->md.parent_oid != InvalidOid)
216+
{
217+
/*
218+
* This is an index on a ENR temp object. We mark the flag by checking
219+
* the parent relations flag.
220+
* If it is an implicit index over tsql table variable, it gets marked
221+
* as false, same as parent since table variable don't follow transactional
222+
* semantics.
223+
*/
224+
EphemeralNamedRelation parent_enr = GetENRTempTableWithOid(enr->md.parent_oid);
225+
if(parent_enr)
226+
enr->md.is_bbf_temp_table = parent_enr->md.is_bbf_temp_table;
227+
else
228+
enr->md.is_bbf_temp_table = false;
229+
} else {
230+
/*
231+
* This is a table or some parent entity. If the name of this table
232+
* starts with '#', this is a tsql temp table.
233+
*/
234+
if (enr->md.name[0] == '#')
235+
enr->md.is_bbf_temp_table = true;
236+
else
237+
enr->md.is_bbf_temp_table = false;
238+
}
219239

220240
if (enr->md.is_bbf_temp_table && GetCurrentSubTransactionId() != InvalidSubTransactionId)
221241
enr->md.created_subid = GetCurrentSubTransactionId();

0 commit comments

Comments
 (0)