Skip to content

Commit 5d1abe6

Browse files
committed
Fix UtilityContainsQuery() to handle CREATE TABLE AS EXECUTE correctly.
The code seems to have been written to handle the pre-parse-analysis representation, where an ExecuteStmt would appear directly under CreateTableAsStmt. But in reality the function is only run on already-parse-analyzed statements, so there will be a Query node in between. We'd not noticed the bug because the function is generally not used at all except in extended query protocol. Per report from Robert Haas and Rushabh Lathia.
1 parent 4e32f8c commit 5d1abe6

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/backend/tcop/utility.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,16 +1508,11 @@ UtilityContainsQuery(Node *parsetree)
15081508
return qry;
15091509

15101510
case T_CreateTableAsStmt:
1511-
/* might or might not contain a Query ... */
15121511
qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
1513-
if (IsA(qry, Query))
1514-
{
1515-
/* Recursion currently can't be necessary here */
1516-
Assert(qry->commandType != CMD_UTILITY);
1517-
return qry;
1518-
}
1519-
Assert(IsA(qry, ExecuteStmt));
1520-
return NULL;
1512+
Assert(IsA(qry, Query));
1513+
if (qry->commandType == CMD_UTILITY)
1514+
return UtilityContainsQuery(qry->utilityStmt);
1515+
return qry;
15211516

15221517
default:
15231518
return NULL;

0 commit comments

Comments
 (0)