aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c3
-rw-r--r--src/backend/commands/async.c26
-rw-r--r--src/backend/commands/createas.c4
-rw-r--r--src/backend/commands/explain.c2
-rw-r--r--src/backend/commands/foreigncmds.c7
-rw-r--r--src/backend/commands/indexcmds.c2
-rw-r--r--src/backend/commands/prepare.c2
-rw-r--r--src/backend/commands/seclabel.c2
-rw-r--r--src/backend/commands/tablecmds.c65
-rw-r--r--src/backend/commands/tsearchcmds.c12
-rw-r--r--src/backend/commands/view.c2
11 files changed, 44 insertions, 83 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index d7004e53138..8d633f25851 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -455,7 +455,8 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
if (indexpr_item == NULL) /* shouldn't happen */
elog(ERROR, "too few entries in indexprs list");
indexkey = (Node *) lfirst(indexpr_item);
- indexpr_item = lnext(indexpr_item);
+ indexpr_item = lnext(indexInfo->ii_Expressions,
+ indexpr_item);
thisdata->vacattrstats[tcnt] =
examine_attribute(Irel[ind], i + 1, indexkey);
if (thisdata->vacattrstats[tcnt] != NULL)
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index 738e6ec7e29..34e5ca9edb3 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -689,7 +689,6 @@ Datum
pg_listening_channels(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
- ListCell **lcp;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
@@ -702,23 +701,17 @@ pg_listening_channels(PG_FUNCTION_ARGS)
/* switch to memory context appropriate for multiple function calls */
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
- /* allocate memory for user context */
- lcp = (ListCell **) palloc(sizeof(ListCell *));
- *lcp = list_head(listenChannels);
- funcctx->user_fctx = (void *) lcp;
-
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
- lcp = (ListCell **) funcctx->user_fctx;
- while (*lcp != NULL)
+ if (funcctx->call_cntr < list_length(listenChannels))
{
- char *channel = (char *) lfirst(*lcp);
+ char *channel = (char *) list_nth(listenChannels,
+ funcctx->call_cntr);
- *lcp = lnext(*lcp);
SRF_RETURN_NEXT(funcctx, CStringGetTextDatum(channel));
}
@@ -1035,23 +1028,20 @@ static void
Exec_UnlistenCommit(const char *channel)
{
ListCell *q;
- ListCell *prev;
if (Trace_notify)
elog(DEBUG1, "Exec_UnlistenCommit(%s,%d)", channel, MyProcPid);
- prev = NULL;
foreach(q, listenChannels)
{
char *lchan = (char *) lfirst(q);
if (strcmp(lchan, channel) == 0)
{
- listenChannels = list_delete_cell(listenChannels, q, prev);
+ listenChannels = foreach_delete_current(listenChannels, q);
pfree(lchan);
break;
}
- prev = q;
}
/*
@@ -1311,9 +1301,9 @@ asyncQueueNotificationToEntry(Notification *n, AsyncQueueEntry *qe)
* database OID in order to fill the page. So every page is always used up to
* the last byte which simplifies reading the page later.
*
- * We are passed the list cell containing the next notification to write
- * and return the first still-unwritten cell back. Eventually we will return
- * NULL indicating all is done.
+ * We are passed the list cell (in pendingNotifies) containing the next
+ * notification to write and return the first still-unwritten cell back.
+ * Eventually we will return NULL indicating all is done.
*
* We are holding AsyncQueueLock already from the caller and grab AsyncCtlLock
* locally in this function.
@@ -1362,7 +1352,7 @@ asyncQueueAddEntries(ListCell *nextNotify)
if (offset + qe.length <= QUEUE_PAGESIZE)
{
/* OK, so advance nextNotify past this item */
- nextNotify = lnext(nextNotify);
+ nextNotify = lnext(pendingNotifies, nextNotify);
}
else
{
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 4c1d909d380..b7d220699fb 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -181,7 +181,7 @@ create_ctas_nodata(List *tlist, IntoClause *into)
if (lc)
{
colname = strVal(lfirst(lc));
- lc = lnext(lc);
+ lc = lnext(into->colNames, lc);
}
else
colname = tle->resname;
@@ -465,7 +465,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
if (lc)
{
colname = strVal(lfirst(lc));
- lc = lnext(lc);
+ lc = lnext(into->colNames, lc);
}
else
colname = NameStr(attribute->attname);
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index dff2ed3f978..62fb3434a32 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -257,7 +257,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
queryString, params, queryEnv);
/* Separate plans with an appropriate separator */
- if (lnext(l) != NULL)
+ if (lnext(rewritten, l) != NULL)
ExplainSeparatePlans(es);
}
}
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index d7bc6e35f02..f96c278a6a1 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -120,11 +120,10 @@ transformGenericOptions(Oid catalogId,
{
DefElem *od = lfirst(optcell);
ListCell *cell;
- ListCell *prev = NULL;
/*
* Find the element in resultOptions. We need this for validation in
- * all cases. Also identify the previous element.
+ * all cases.
*/
foreach(cell, resultOptions)
{
@@ -132,8 +131,6 @@ transformGenericOptions(Oid catalogId,
if (strcmp(def->defname, od->defname) == 0)
break;
- else
- prev = cell;
}
/*
@@ -150,7 +147,7 @@ transformGenericOptions(Oid catalogId,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("option \"%s\" not found",
od->defname)));
- resultOptions = list_delete_cell(resultOptions, cell, prev);
+ resultOptions = list_delete_cell(resultOptions, cell);
break;
case DEFELEM_SET:
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 6fa5738bbfb..fd299273c5a 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -1793,7 +1793,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo,
indexInfo->ii_ExclusionOps[attn] = opid;
indexInfo->ii_ExclusionProcs[attn] = get_opcode(opid);
indexInfo->ii_ExclusionStrats[attn] = strat;
- nextExclOp = lnext(nextExclOp);
+ nextExclOp = lnext(exclusionOpNames, nextExclOp);
}
/*
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index c278ee7318b..c12b6137633 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -682,7 +682,7 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
/* No need for CommandCounterIncrement, as ExplainOnePlan did it */
/* Separate plans with an appropriate separator */
- if (lnext(p) != NULL)
+ if (lnext(plan_list, p) != NULL)
ExplainSeparatePlans(es);
}
diff --git a/src/backend/commands/seclabel.c b/src/backend/commands/seclabel.c
index 9db82280287..63219ad589f 100644
--- a/src/backend/commands/seclabel.c
+++ b/src/backend/commands/seclabel.c
@@ -58,7 +58,7 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("no security label providers have been loaded")));
- if (lnext(list_head(label_provider_list)) != NULL)
+ if (list_length(label_provider_list) != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("must specify provider when multiple security label providers have been loaded")));
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 0f1a9f0e548..2e792edbcfa 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -2040,13 +2040,13 @@ static List *
MergeAttributes(List *schema, List *supers, char relpersistence,
bool is_partition, List **supconstr)
{
- ListCell *entry;
List *inhSchema = NIL;
List *constraints = NIL;
bool have_bogus_defaults = false;
int child_attno;
static Node bogus_marker = {0}; /* marks conflicting defaults */
List *saved_schema = NIL;
+ ListCell *entry;
/*
* Check for and reject tables with too many columns. We perform this
@@ -2071,12 +2071,17 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
* Although we might consider merging such entries in the same way that we
* handle name conflicts for inherited attributes, it seems to make more
* sense to assume such conflicts are errors.
+ *
+ * We don't use foreach() here because we have two nested loops over the
+ * schema list, with possible element deletions in the inner one. If we
+ * used foreach_delete_current() it could only fix up the state of one of
+ * the loops, so it seems cleaner to use looping over list indexes for
+ * both loops. Note that any deletion will happen beyond where the outer
+ * loop is, so its index never needs adjustment.
*/
- foreach(entry, schema)
+ for (int coldefpos = 0; coldefpos < list_length(schema); coldefpos++)
{
- ColumnDef *coldef = lfirst(entry);
- ListCell *rest = lnext(entry);
- ListCell *prev = entry;
+ ColumnDef *coldef = list_nth_node(ColumnDef, schema, coldefpos);
if (!is_partition && coldef->typeName == NULL)
{
@@ -2092,11 +2097,10 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->colname)));
}
- while (rest != NULL)
+ /* restpos scans all entries beyond coldef; incr is in loop body */
+ for (int restpos = coldefpos + 1; restpos < list_length(schema);)
{
- ColumnDef *restdef = lfirst(rest);
- ListCell *next = lnext(rest); /* need to save it in case we
- * delete it */
+ ColumnDef *restdef = list_nth_node(ColumnDef, schema, restpos);
if (strcmp(coldef->colname, restdef->colname) == 0)
{
@@ -2110,13 +2114,7 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
coldef->cooked_default = restdef->cooked_default;
coldef->constraints = restdef->constraints;
coldef->is_from_type = false;
- schema = list_delete_cell(schema, rest, prev);
-
- /*
- * As two elements are merged and one is removed, we
- * should never finish with an empty list.
- */
- Assert(schema != NIL);
+ schema = list_delete_nth_cell(schema, restpos);
}
else
ereport(ERROR,
@@ -2124,8 +2122,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence,
errmsg("column \"%s\" specified more than once",
coldef->colname)));
}
- prev = rest;
- rest = next;
+ else
+ restpos++;
}
}
@@ -7866,7 +7864,8 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
* assess ppeqop or ffeqop, which RI_Initial_Check() does not use.
*/
old_check_ok = (pfeqop == lfirst_oid(old_pfeqop_item));
- old_pfeqop_item = lnext(old_pfeqop_item);
+ old_pfeqop_item = lnext(fkconstraint->old_conpfeqop,
+ old_pfeqop_item);
}
if (old_check_ok)
{
@@ -14619,12 +14618,8 @@ void
AtEOXact_on_commit_actions(bool isCommit)
{
ListCell *cur_item;
- ListCell *prev_item;
-
- prev_item = NULL;
- cur_item = list_head(on_commits);
- while (cur_item != NULL)
+ foreach(cur_item, on_commits)
{
OnCommitItem *oc = (OnCommitItem *) lfirst(cur_item);
@@ -14632,20 +14627,14 @@ AtEOXact_on_commit_actions(bool isCommit)
oc->creating_subid != InvalidSubTransactionId)
{
/* cur_item must be removed */
- on_commits = list_delete_cell(on_commits, cur_item, prev_item);
+ on_commits = foreach_delete_current(on_commits, cur_item);
pfree(oc);
- if (prev_item)
- cur_item = lnext(prev_item);
- else
- cur_item = list_head(on_commits);
}
else
{
/* cur_item must be preserved */
oc->creating_subid = InvalidSubTransactionId;
oc->deleting_subid = InvalidSubTransactionId;
- prev_item = cur_item;
- cur_item = lnext(prev_item);
}
}
}
@@ -14662,24 +14651,16 @@ AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid,
SubTransactionId parentSubid)
{
ListCell *cur_item;
- ListCell *prev_item;
- prev_item = NULL;
- cur_item = list_head(on_commits);
-
- while (cur_item != NULL)
+ foreach(cur_item, on_commits)
{
OnCommitItem *oc = (OnCommitItem *) lfirst(cur_item);
if (!isCommit && oc->creating_subid == mySubid)
{
/* cur_item must be removed */
- on_commits = list_delete_cell(on_commits, cur_item, prev_item);
+ on_commits = foreach_delete_current(on_commits, cur_item);
pfree(oc);
- if (prev_item)
- cur_item = lnext(prev_item);
- else
- cur_item = list_head(on_commits);
}
else
{
@@ -14688,8 +14669,6 @@ AtEOSubXact_on_commit_actions(bool isCommit, SubTransactionId mySubid,
oc->creating_subid = parentSubid;
if (oc->deleting_subid == mySubid)
oc->deleting_subid = isCommit ? parentSubid : InvalidSubTransactionId;
- prev_item = cur_item;
- cur_item = lnext(prev_item);
}
}
}
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 11a7f29eafa..5d6528f9cf8 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -575,22 +575,16 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
{
DefElem *defel = (DefElem *) lfirst(pl);
ListCell *cell;
- ListCell *prev;
- ListCell *next;
/*
* Remove any matches ...
*/
- prev = NULL;
- for (cell = list_head(dictoptions); cell; cell = next)
+ foreach(cell, dictoptions)
{
DefElem *oldel = (DefElem *) lfirst(cell);
- next = lnext(cell);
if (strcmp(oldel->defname, defel->defname) == 0)
- dictoptions = list_delete_cell(dictoptions, cell, prev);
- else
- prev = cell;
+ dictoptions = foreach_delete_current(dictoptions, cell);
}
/*
@@ -1558,7 +1552,7 @@ serialize_deflist(List *deflist)
appendStringInfoChar(&buf, ch);
}
appendStringInfoChar(&buf, '\'');
- if (lnext(l) != NULL)
+ if (lnext(deflist, l) != NULL)
appendStringInfoString(&buf, ", ");
}
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 87ed453649b..9773bdc1c3d 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -522,7 +522,7 @@ DefineView(ViewStmt *stmt, const char *queryString,
if (te->resjunk)
continue;
te->resname = pstrdup(strVal(lfirst(alist_item)));
- alist_item = lnext(alist_item);
+ alist_item = lnext(stmt->aliases, alist_item);
if (alist_item == NULL)
break; /* done assigning aliases */
}