mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Use the properly transformed RangeVar for expandTableLikeClause().
transformCreateStmt() adjusts the transformed statement's RangeVar
to specify the target schema explicitly, for the express reason
of making sure that auxiliary statements derived by parse
transformation operate on the right table. But the refactoring
I did in commit 502898192
got this wrong and passed the untransformed
RangeVar to expandTableLikeClause(). This could lead to assertion
failures or weird misbehavior if the wrong table was accessed.
Per report from Alexander Lakhin. Like the previous patch, back-patch
to all supported branches.
Discussion: https://postgr.es/m/05051f9d-b32b-cb35-6735-0e9f2ab86b5f@gmail.com
This commit is contained in:
@ -995,6 +995,7 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
{
|
||||
List *stmts;
|
||||
ListCell *l;
|
||||
RangeVar *table_rv = NULL;
|
||||
|
||||
/* Run parse analysis ... */
|
||||
stmts = transformCreateStmt((CreateStmt *) parsetree,
|
||||
@ -1007,11 +1008,15 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
|
||||
if (IsA(stmt, CreateStmt))
|
||||
{
|
||||
CreateStmt *cstmt = (CreateStmt *) stmt;
|
||||
Datum toast_options;
|
||||
static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
|
||||
|
||||
/* Remember transformed RangeVar for LIKE */
|
||||
table_rv = cstmt->relation;
|
||||
|
||||
/* Create the table itself */
|
||||
address = DefineRelation((CreateStmt *) stmt,
|
||||
address = DefineRelation(cstmt,
|
||||
RELKIND_RELATION,
|
||||
InvalidOid, NULL,
|
||||
queryString);
|
||||
@ -1030,7 +1035,7 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
* table
|
||||
*/
|
||||
toast_options = transformRelOptions((Datum) 0,
|
||||
((CreateStmt *) stmt)->options,
|
||||
cstmt->options,
|
||||
"toast",
|
||||
validnsps,
|
||||
true,
|
||||
@ -1044,12 +1049,17 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
}
|
||||
else if (IsA(stmt, CreateForeignTableStmt))
|
||||
{
|
||||
CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) stmt;
|
||||
|
||||
/* Remember transformed RangeVar for LIKE */
|
||||
table_rv = cstmt->base.relation;
|
||||
|
||||
/* Create the table itself */
|
||||
address = DefineRelation((CreateStmt *) stmt,
|
||||
address = DefineRelation(&cstmt->base,
|
||||
RELKIND_FOREIGN_TABLE,
|
||||
InvalidOid, NULL,
|
||||
queryString);
|
||||
CreateForeignTable((CreateForeignTableStmt *) stmt,
|
||||
CreateForeignTable(cstmt,
|
||||
address.objectId);
|
||||
EventTriggerCollectSimpleCommand(address,
|
||||
secondaryObject,
|
||||
@ -1064,10 +1074,11 @@ ProcessUtilitySlow(ParseState *pstate,
|
||||
* to-do list.
|
||||
*/
|
||||
TableLikeClause *like = (TableLikeClause *) stmt;
|
||||
RangeVar *rv = ((CreateStmt *) parsetree)->relation;
|
||||
List *morestmts;
|
||||
|
||||
morestmts = expandTableLikeClause(rv, like);
|
||||
Assert(table_rv != NULL);
|
||||
|
||||
morestmts = expandTableLikeClause(table_rv, like);
|
||||
stmts = list_concat(stmts, morestmts);
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user