diff options
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r-- | src/backend/tcop/utility.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 042feb96280..7c8eee07e80 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -963,17 +963,22 @@ ProcessUtilitySlow(Node *parsetree, case T_CreateForeignTableStmt: { List *stmts; - ListCell *l; RangeVar *table_rv = NULL; /* Run parse analysis ... */ stmts = transformCreateStmt((CreateStmt *) parsetree, queryString); - /* ... and do it */ - foreach(l, stmts) + /* + * ... and do it. We can't use foreach() because we may + * modify the list midway through, so pick off the + * elements one at a time, the hard way. + */ + while (stmts != NIL) { - Node *stmt = (Node *) lfirst(l); + Node *stmt = (Node *) linitial(stmts); + + stmts = list_delete_first(stmts); if (IsA(stmt, CreateStmt)) { @@ -1037,8 +1042,8 @@ ProcessUtilitySlow(Node *parsetree, /* * Do delayed processing of LIKE options. This * will result in additional sub-statements for us - * to process. We can just tack those onto the - * to-do list. + * to process. Those should get done before any + * remaining actions, so prepend them to "stmts". */ TableLikeClause *like = (TableLikeClause *) stmt; List *morestmts; @@ -1046,14 +1051,7 @@ ProcessUtilitySlow(Node *parsetree, Assert(table_rv != NULL); morestmts = expandTableLikeClause(table_rv, like); - stmts = list_concat(stmts, morestmts); - - /* - * We don't need a CCI now, besides which the "l" - * list pointer is now possibly invalid, so just - * skip the CCI test below. - */ - continue; + stmts = list_concat(morestmts, stmts); } else { @@ -1071,7 +1069,7 @@ ProcessUtilitySlow(Node *parsetree, } /* Need CCI between commands */ - if (lnext(l) != NULL) + if (stmts != NIL) CommandCounterIncrement(); } |