On Sat, Aug 20, 2022 at 09:17:41PM +1200, David Rowley wrote:
> On Fri, 19 Aug 2022 at 16:28, Justin Pryzby <[email protected]> wrote:
> > Let me know what I can do when it's time for round two.
>
> I pushed the modified 0001-0008 patches earlier today and also the one
> I wrote to fixup the 36 warnings about "expected" being shadowed.
Thank you
> I looked through a bunch of your remaining patches and was a bit
> unexcited to see many more renaming such as:
Yes - after Michael said that was the sane procedure, I had rearranged the
patch series to present eariler those patches first which renamed variables ..
> However, one category of these changes that I do like are the ones
> where we can move the variable into an inner scope.
There are a lot of these, which ISTM is a good thing.
This fixes about half of the remaining warnings.
https://github.com/justinpryzby/postgres/tree/avoid-shadow-vars
You could review without applying the patches, on the webpage or (probably
better) by adding as a git remote. Attached is a squished version.
--
Justin
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index e88f7efa7e4..69f21abfb59 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -372,7 +372,6 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
**nullkeys;
int *nkeys,
*nnullkeys;
- int keyno;
char *ptr;
Size len;
char *tmp PG_USED_FOR_ASSERTS_ONLY;
@@ -454,7 +453,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
/* Preprocess the scan keys - split them into per-attribute arrays. */
- for (keyno = 0; keyno < scan->numberOfKeys; keyno++)
+ for (int keyno = 0; keyno < scan->numberOfKeys; keyno++)
{
ScanKey key = &scan->keyData[keyno];
AttrNumber keyattno = key->sk_attno;
diff --git a/src/backend/access/brin/brin_minmax_multi.c
b/src/backend/access/brin/brin_minmax_multi.c
index 10d4f17bc6f..524c1846b83 100644
--- a/src/backend/access/brin/brin_minmax_multi.c
+++ b/src/backend/access/brin/brin_minmax_multi.c
@@ -582,7 +582,6 @@ brin_range_serialize(Ranges *range)
int typlen;
bool typbyval;
- int i;
char *ptr;
/* simple sanity checks */
@@ -621,18 +620,14 @@ brin_range_serialize(Ranges *range)
*/
if (typlen == -1) /* varlena */
{
- int i;
-
- for (i = 0; i < nvalues; i++)
+ for (int i = 0; i < nvalues; i++)
{
len += VARSIZE_ANY(range->values[i]);
}
}
else if (typlen == -2) /* cstring */
{
- int i;
-
- for (i = 0; i < nvalues; i++)
+ for (int i = 0; i < nvalues; i++)
{
/* don't forget to include the null terminator ;-) */
len += strlen(DatumGetCString(range->values[i])) + 1;
@@ -662,7 +657,7 @@ brin_range_serialize(Ranges *range)
*/
ptr = serialized->data; /* start of the serialized data */
- for (i = 0; i < nvalues; i++)
+ for (int i = 0; i < nvalues; i++)
{
if (typbyval) /* simple by-value data types */
{
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 5866c6aaaf7..30069f139c7 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -234,7 +234,6 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE
*giststate,
Page page = BufferGetPage(buffer);
bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
XLogRecPtr recptr;
- int i;
bool is_split;
/*
@@ -420,7 +419,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE
*giststate,
{
char *data = (char *) (ptr->list);
- for (i = 0; i < ptr->block.num; i++)
+ for (int i = 0; i < ptr->block.num; i++)
{
IndexTuple thistup = (IndexTuple) data;
diff --git a/src/backend/access/transam/xlog.c
b/src/backend/access/transam/xlog.c
index 87b243e0d4b..46e3bb55ebb 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3036,8 +3036,6 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID
logtli,
pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_SYNC);
if (pg_fsync(fd) != 0)
{
- int save_errno = errno;
-
close(fd);
errno = save_errno;
ereport(ERROR,
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 9b03579e6e0..9a83ebf3231 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1818,19 +1818,19 @@ heap_drop_with_catalog(Oid relid)
*/
if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
{
- Relation rel;
- HeapTuple tuple;
+ Relation pg_foreign_table;
+ HeapTuple foreigntuple;
- rel = table_open(ForeignTableRelationId, RowExclusiveLock);
+ pg_foreign_table = table_open(ForeignTableRelationId,
RowExclusiveLock);
- tuple = SearchSysCache1(FOREIGNTABLEREL,
ObjectIdGetDatum(relid));
- if (!HeapTupleIsValid(tuple))
+ foreigntuple = SearchSysCache1(FOREIGNTABLEREL,
ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(foreigntuple))
elog(ERROR, "cache lookup failed for foreign table %u",
relid);
- CatalogTupleDelete(rel, &tuple->t_self);
+ CatalogTupleDelete(pg_foreign_table, &foreigntuple->t_self);
- ReleaseSysCache(tuple);
- table_close(rel, RowExclusiveLock);
+ ReleaseSysCache(foreigntuple);
+ table_close(pg_foreign_table, RowExclusiveLock);
}
/*
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c
index a976008b3d4..e8bb168aea8 100644
--- a/src/backend/commands/copyfrom.c
+++ b/src/backend/commands/copyfrom.c
@@ -1202,7 +1202,6 @@ BeginCopyFrom(ParseState *pstate,
num_defaults;
FmgrInfo *in_functions;
Oid *typioparams;
- int attnum;
Oid in_func_oid;
int *defmap;
ExprState **defexprs;
@@ -1401,7 +1400,7 @@ BeginCopyFrom(ParseState *pstate,
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
- for (attnum = 1; attnum <= num_phys_attrs; attnum++)
+ for (int attnum = 1; attnum <= num_phys_attrs; attnum++)
{
Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 667f2a4cd16..3c6e09815e0 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -565,7 +565,6 @@ DefineIndex(Oid relationId,
Oid root_save_userid;
int root_save_sec_context;
int root_save_nestlevel;
- int i;
root_save_nestlevel = NewGUCNestLevel();
@@ -1047,7 +1046,7 @@ DefineIndex(Oid relationId,
* We disallow indexes on system columns. They would not necessarily
get
* updated correctly, and they don't seem useful anyway.
*/
- for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
+ for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
{
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
@@ -1067,7 +1066,7 @@ DefineIndex(Oid relationId,
pull_varattnos((Node *) indexInfo->ii_Expressions, 1,
&indexattrs);
pull_varattnos((Node *) indexInfo->ii_Predicate, 1,
&indexattrs);
- for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
+ for (int i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
{
if (bms_is_member(i -
FirstLowInvalidHeapAttributeNumber,
indexattrs))
@@ -1243,7 +1242,7 @@ DefineIndex(Oid relationId,
* If none matches, build a new index by calling
ourselves
* recursively with the same options (except for the
index name).
*/
- for (i = 0; i < nparts; i++)
+ for (int i = 0; i < nparts; i++)
{
Oid childRelid =
part_oids[i];
Relation childrel;
diff --git a/src/backend/commands/publicationcmds.c
b/src/backend/commands/publicationcmds.c
index 8b574b86c47..f9366f588fb 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -106,7 +106,7 @@ parse_publication_options(ParseState *pstate,
{
char *publish;
List *publish_list;
- ListCell *lc;
+ ListCell *lc2;
if (*publish_given)
errorConflictingDefElem(defel, pstate);
@@ -129,9 +129,9 @@ parse_publication_options(ParseState *pstate,
errmsg("invalid list syntax
for \"publish\" option")));
/* Process the option list. */
- foreach(lc, publish_list)
+ foreach(lc2, publish_list)
{
- char *publish_opt = (char *) lfirst(lc);
+ char *publish_opt = (char *) lfirst(lc2);
if (strcmp(publish_opt, "insert") == 0)
pubactions->pubinsert = true;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9be04c8a1e7..7535b86bcae 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -10223,7 +10223,7 @@ CloneFkReferencing(List **wqueue, Relation parentRel,
Relation partRel)
Oid constrOid;
ObjectAddress address,
referenced;
- ListCell *cell;
+ ListCell *lc;
Oid insertTriggerOid,
updateTriggerOid;
@@ -10276,9 +10276,9 @@ CloneFkReferencing(List **wqueue, Relation parentRel,
Relation partRel)
* don't need to recurse to partitions for this constraint.
*/
attached = false;
- foreach(cell, partFKs)
+ foreach(lc, partFKs)
{
- ForeignKeyCacheInfo *fk =
lfirst_node(ForeignKeyCacheInfo, cell);
+ ForeignKeyCacheInfo *fk =
lfirst_node(ForeignKeyCacheInfo, lc);
if (tryAttachPartitionForeignKey(fk,
RelationGetRelid(partRel),
@@ -16796,7 +16796,6 @@ PreCommit_on_commit_actions(void)
if (oids_to_drop != NIL)
{
ObjectAddresses *targetObjects = new_object_addresses();
- ListCell *l;
foreach(l, oids_to_drop)
{
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 62a09fb131b..f1801a160ed 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -1149,7 +1149,6 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char
*queryString,
PartitionDesc partdesc = RelationGetPartitionDesc(rel, true);
List *idxs = NIL;
List *childTbls = NIL;
- ListCell *l;
int i;
MemoryContext oldcxt,
perChildCxt;
@@ -1181,7 +1180,8 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char
*queryString,
for (i = 0; i < partdesc->nparts; i++)
{
Oid indexOnChild = InvalidOid;
- ListCell *l2;
+ ListCell *l,
+ *l2;
CreateTrigStmt *childStmt;
Relation childTbl;
Node *qual;
@@ -1726,9 +1726,9 @@ renametrig_partition(Relation tgrel, Oid partitionId, Oid
parentTriggerOid,
for (int i = 0; i < partdesc->nparts; i++)
{
- Oid partitionId =
partdesc->oids[i];
+ Oid partid =
partdesc->oids[i];
- renametrig_partition(tgrel, partitionId,
tgform->oid, newname,
+ renametrig_partition(tgrel, partid,
tgform->oid, newname,
NameStr(tgform->tgname));
}
}
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index dbdfe8bd2d4..3670d1f1861 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -233,8 +233,6 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool
isTopLevel)
*/
if (!(params.options & VACOPT_ANALYZE))
{
- ListCell *lc;
-
foreach(lc, vacstmt->rels)
{
VacuumRelation *vrel = lfirst_node(VacuumRelation, lc);
diff --git a/src/backend/executor/execPartition.c
b/src/backend/executor/execPartition.c
index ac03271882f..901dd435efd 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -768,7 +768,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState
*estate,
{
List *onconflset;
List *onconflcols;
- bool found_whole_row;
/*
* Translate expressions in onConflictSet to
account for
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 96d200e4461..736082c8fb3 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -1296,13 +1296,12 @@ finalize_aggregates(AggState *aggstate,
Datum *aggvalues = econtext->ecxt_aggvalues;
bool *aggnulls = econtext->ecxt_aggnulls;
int aggno;
- int transno;
/*
* If there were any DISTINCT and/or ORDER BY aggregates, sort their
* inputs and run the transition functions.
*/
- for (transno = 0; transno < aggstate->numtrans; transno++)
+ for (int transno = 0; transno < aggstate->numtrans; transno++)
{
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
AggStatePerGroup pergroupstate;
@@ -3188,7 +3187,6 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
int numGroupingSets = 1;
int numPhases;
int numHashes;
- int i = 0;
int j = 0;
bool use_hashing = (node->aggstrategy == AGG_HASHED ||
node->aggstrategy ==
AGG_MIXED);
@@ -3279,7 +3277,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
ExecAssignExprContext(estate, &aggstate->ss.ps);
aggstate->tmpcontext = aggstate->ss.ps.ps_ExprContext;
- for (i = 0; i < numGroupingSets; ++i)
+ for (int i = 0; i < numGroupingSets; ++i)
{
ExecAssignExprContext(estate, &aggstate->ss.ps);
aggstate->aggcontexts[i] = aggstate->ss.ps.ps_ExprContext;
@@ -3419,10 +3417,10 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
AggStatePerPhase phasedata = &aggstate->phases[0];
AggStatePerHash perhash;
Bitmapset *cols = NULL;
+ int setno = phasedata->numsets++;
Assert(phase == 0);
- i = phasedata->numsets++;
- perhash = &aggstate->perhash[i];
+ perhash = &aggstate->perhash[setno];
/* phase 0 always points to the "real" Agg in the hash
case */
phasedata->aggnode = node;
@@ -3431,12 +3429,12 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
/* but the actual Agg node representing this hash is
saved here */
perhash->aggnode = aggnode;
- phasedata->gset_lengths[i] = perhash->numCols =
aggnode->numCols;
+ phasedata->gset_lengths[setno] = perhash->numCols =
aggnode->numCols;
for (j = 0; j < aggnode->numCols; ++j)
cols = bms_add_member(cols,
aggnode->grpColIdx[j]);
- phasedata->grouped_cols[i] = cols;
+ phasedata->grouped_cols[setno] = cols;
all_grouped_cols = bms_add_members(all_grouped_cols,
cols);
continue;
@@ -3450,6 +3448,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
if (num_sets)
{
+ int i;
phasedata->gset_lengths = palloc(num_sets *
sizeof(int));
phasedata->grouped_cols = palloc(num_sets *
sizeof(Bitmapset *));
@@ -3535,9 +3534,11 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
/*
* Convert all_grouped_cols to a descending-order list.
*/
- i = -1;
- while ((i = bms_next_member(all_grouped_cols, i)) >= 0)
- aggstate->all_grouped_cols = lcons_int(i,
aggstate->all_grouped_cols);
+ {
+ int i = -1;
+ while ((i = bms_next_member(all_grouped_cols, i)) >= 0)
+ aggstate->all_grouped_cols = lcons_int(i,
aggstate->all_grouped_cols);
+ }
/*
* Set up aggregate-result storage in the output expr context, and also
@@ -3561,7 +3562,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
if (node->aggstrategy != AGG_HASHED)
{
- for (i = 0; i < numGroupingSets; i++)
+ for (int i = 0; i < numGroupingSets; i++)
{
pergroups[i] = (AggStatePerGroup)
palloc0(sizeof(AggStatePerGroupData)
* numaggs);
diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index 1545ff9f161..f9d40fa1a0d 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1650,16 +1650,16 @@ interpret_ident_response(const char *ident_response,
return false;
else
{
- int i;
/* Index into *ident_user */
+ int j;
/* Index into *ident_user */
cursor++; /* Go over
colon */
while (pg_isblank(*cursor))
cursor++; /* skip
blanks */
/* Rest of line is user name.
Copy it over. */
- i = 0;
+ j = 0;
while (*cursor != '\r' && i <
IDENT_USERNAME_MAX)
- ident_user[i++] =
*cursor++;
- ident_user[i] = '\0';
+ ident_user[j++] =
*cursor++;
+ ident_user[j] = '\0';
return true;
}
}
diff --git a/src/backend/optimizer/path/costsize.c
b/src/backend/optimizer/path/costsize.c
index 1e94c5aa7c4..74adc4f3946 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -2447,7 +2447,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int
parallel_workers)
int arrlen;
ListCell *l;
ListCell *cell;
- int i;
int path_index;
int min_index;
int max_index;
@@ -2486,7 +2485,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int
parallel_workers)
for_each_cell(l, subpaths, cell)
{
Path *subpath = (Path *) lfirst(l);
- int i;
/* Consider only the non-partial paths */
if (path_index++ == numpaths)
@@ -2495,7 +2493,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int
parallel_workers)
costarr[min_index] += subpath->total_cost;
/* Update the new min cost array index */
- for (min_index = i = 0; i < arrlen; i++)
+ min_index = 0;
+ for (int i = 0; i < arrlen; i++)
{
if (costarr[i] < costarr[min_index])
min_index = i;
@@ -2503,7 +2502,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int
parallel_workers)
}
/* Return the highest cost from the array */
- for (max_index = i = 0; i < arrlen; i++)
+ max_index = 0;
+ for (int i = 0; i < arrlen; i++)
{
if (costarr[i] > costarr[max_index])
max_index = i;
@@ -2545,10 +2545,10 @@ cost_append(AppendPath *apath, PlannerInfo *root)
/* Compute rows and costs as sums of subplan rows and
costs. */
foreach(l, apath->subpaths)
{
- Path *subpath = (Path *) lfirst(l);
+ Path *sub = (Path *) lfirst(l);
- apath->path.rows += subpath->rows;
- apath->path.total_cost += subpath->total_cost;
+ apath->path.rows += sub->rows;
+ apath->path.total_cost += sub->total_cost;
}
}
else
diff --git a/src/backend/optimizer/path/indxpath.c
b/src/backend/optimizer/path/indxpath.c
index 7d176e7b00a..8ba27a98b42 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -361,7 +361,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
if (bitjoinpaths != NIL)
{
List *all_path_outers;
- ListCell *lc;
/* Identify each distinct parameterization seen in bitjoinpaths
*/
all_path_outers = NIL;
diff --git a/src/backend/optimizer/path/tidpath.c
b/src/backend/optimizer/path/tidpath.c
index 279ca1f5b44..23194d6e007 100644
--- a/src/backend/optimizer/path/tidpath.c
+++ b/src/backend/optimizer/path/tidpath.c
@@ -305,10 +305,10 @@ TidQualFromRestrictInfoList(PlannerInfo *root, List
*rlist, RelOptInfo *rel)
}
else
{
- RestrictInfo *rinfo =
castNode(RestrictInfo, orarg);
+ RestrictInfo *list =
castNode(RestrictInfo, orarg);
-
Assert(!restriction_is_or_clause(rinfo));
- sublist = TidQualFromRestrictInfo(root,
rinfo, rel);
+ Assert(!restriction_is_or_clause(list));
+ sublist = TidQualFromRestrictInfo(root,
list, rel);
}
/*
diff --git a/src/backend/optimizer/plan/planner.c
b/src/backend/optimizer/plan/planner.c
index cf9e0a74dbf..e969f2be3fe 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1994,8 +1994,6 @@ preprocess_grouping_sets(PlannerInfo *root)
if (parse->groupClause)
{
- ListCell *lc;
-
foreach(lc, parse->groupClause)
{
SortGroupClause *gc = lfirst_node(SortGroupClause, lc);
@@ -3458,16 +3456,16 @@ get_number_of_groups(PlannerInfo *root,
foreach(lc, gd->rollups)
{
RollupData *rollup = lfirst_node(RollupData,
lc);
- ListCell *lc;
+ ListCell *lc3;
groupExprs =
get_sortgrouplist_exprs(rollup->groupClause,
target_list);
rollup->numGroups = 0.0;
- forboth(lc, rollup->gsets, lc2,
rollup->gsets_data)
+ forboth(lc3, rollup->gsets, lc2,
rollup->gsets_data)
{
- List *gset = (List *) lfirst(lc);
+ List *gset = (List *) lfirst(lc3);
GroupingSetData *gs =
lfirst_node(GroupingSetData, lc2);
double numGroups =
estimate_num_groups(root,
groupExprs,
@@ -3484,8 +3482,6 @@ get_number_of_groups(PlannerInfo *root,
if (gd->hash_sets_idx)
{
- ListCell *lc;
-
gd->dNumHashGroups = 0;
groupExprs =
get_sortgrouplist_exprs(parse->groupClause,
@@ -5034,11 +5030,11 @@ create_ordered_paths(PlannerInfo *root,
*/
if (enable_incremental_sort && list_length(root->sort_pathkeys)
> 1)
{
- ListCell *lc;
+ ListCell *lc2;
- foreach(lc, input_rel->partial_pathlist)
+ foreach(lc2, input_rel->partial_pathlist)
{
- Path *input_path = (Path *) lfirst(lc);
+ Path *input_path = (Path *) lfirst(lc2);
Path *sorted_path;
bool is_sorted;
int presorted_keys;
@@ -7607,7 +7603,7 @@ apply_scanjoin_target_to_paths(PlannerInfo *root,
AppendRelInfo **appinfos;
int nappinfos;
List *child_scanjoin_targets = NIL;
- ListCell *lc;
+ ListCell *lc2;
Assert(child_rel != NULL);
@@ -7618,9 +7614,9 @@ apply_scanjoin_target_to_paths(PlannerInfo *root,
/* Translate scan/join targets for this child. */
appinfos = find_appinfos_by_relids(root,
child_rel->relids,
&nappinfos);
- foreach(lc, scanjoin_targets)
+ foreach(lc2, scanjoin_targets)
{
- PathTarget *target = lfirst_node(PathTarget,
lc);
+ PathTarget *target = lfirst_node(PathTarget,
lc2);
target = copy_pathtarget(target);
target->exprs = (List *)
diff --git a/src/backend/optimizer/plan/subselect.c
b/src/backend/optimizer/plan/subselect.c
index df4ca129191..b15ecc83971 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -2402,7 +2402,7 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_FunctionScan:
{
FunctionScan *fscan = (FunctionScan *) plan;
- ListCell *lc;
+ ListCell *lc; //
/*
* Call finalize_primnode independently on each
function
@@ -2510,7 +2510,7 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_CustomScan:
{
CustomScan *cscan = (CustomScan *) plan;
- ListCell *lc;
+ ListCell *lc; //
finalize_primnode((Node *) cscan->custom_exprs,
&context);
@@ -2554,8 +2554,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_Append:
{
- ListCell *l;
-
foreach(l, ((Append *) plan)->appendplans)
{
context.paramids =
@@ -2571,8 +2569,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_MergeAppend:
{
- ListCell *l;
-
foreach(l, ((MergeAppend *) plan)->mergeplans)
{
context.paramids =
@@ -2588,8 +2584,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_BitmapAnd:
{
- ListCell *l;
-
foreach(l, ((BitmapAnd *) plan)->bitmapplans)
{
context.paramids =
@@ -2605,8 +2599,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_BitmapOr:
{
- ListCell *l;
-
foreach(l, ((BitmapOr *) plan)->bitmapplans)
{
context.paramids =
@@ -2622,8 +2614,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
case T_NestLoop:
{
- ListCell *l;
-
finalize_primnode((Node *) ((Join *)
plan)->joinqual,
&context);
/* collect set of params that will be passed to
right child */
diff --git a/src/backend/optimizer/prep/prepunion.c
b/src/backend/optimizer/prep/prepunion.c
index 043181b586b..f97c2f5256c 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -653,15 +653,14 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo
*root,
if (partial_paths_valid)
{
Path *ppath;
- ListCell *lc;
int parallel_workers = 0;
/* Find the highest number of workers requested for any
subpath. */
foreach(lc, partial_pathlist)
{
- Path *path = lfirst(lc);
+ Path *partial_path = lfirst(lc);
- parallel_workers = Max(parallel_workers,
path->parallel_workers);
+ parallel_workers = Max(parallel_workers,
partial_path->parallel_workers);
}
Assert(parallel_workers > 0);
diff --git a/src/backend/optimizer/util/paramassign.c
b/src/backend/optimizer/util/paramassign.c
index 8e2d4bf5158..933460989b3 100644
--- a/src/backend/optimizer/util/paramassign.c
+++ b/src/backend/optimizer/util/paramassign.c
@@ -437,16 +437,16 @@ process_subquery_nestloop_params(PlannerInfo *root, List
*subplan_params)
{
Var *var = (Var *) pitem->item;
NestLoopParam *nlp;
- ListCell *lc;
+ ListCell *lc2;
/* If not from a nestloop outer rel, complain */
if (!bms_is_member(var->varno, root->curOuterRels))
elog(ERROR, "non-LATERAL parameter required by
subquery");
/* Is this param already listed in
root->curOuterParams? */
- foreach(lc, root->curOuterParams)
+ foreach(lc2, root->curOuterParams)
{
- nlp = (NestLoopParam *) lfirst(lc);
+ nlp = (NestLoopParam *) lfirst(lc2);
if (nlp->paramno == pitem->paramId)
{
Assert(equal(var, nlp->paramval));
@@ -454,7 +454,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List
*subplan_params)
break;
}
}
- if (lc == NULL)
+ if (lc2 == NULL)
{
/* No, so add it */
nlp = makeNode(NestLoopParam);
@@ -467,7 +467,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List
*subplan_params)
{
PlaceHolderVar *phv = (PlaceHolderVar *) pitem->item;
NestLoopParam *nlp;
- ListCell *lc;
+ ListCell *lc2;
/* If not from a nestloop outer rel, complain */
if (!bms_is_subset(find_placeholder_info(root,
phv)->ph_eval_at,
@@ -475,9 +475,9 @@ process_subquery_nestloop_params(PlannerInfo *root, List
*subplan_params)
elog(ERROR, "non-LATERAL parameter required by
subquery");
/* Is this param already listed in
root->curOuterParams? */
- foreach(lc, root->curOuterParams)
+ foreach(lc2, root->curOuterParams)
{
- nlp = (NestLoopParam *) lfirst(lc);
+ nlp = (NestLoopParam *) lfirst(lc2);
if (nlp->paramno == pitem->paramId)
{
Assert(equal(phv, nlp->paramval));
@@ -485,7 +485,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List
*subplan_params)
break;
}
}
- if (lc == NULL)
+ if (lc2 == NULL)
{
/* No, so add it */
nlp = makeNode(NestLoopParam);
diff --git a/src/backend/parser/parse_clause.c
b/src/backend/parser/parse_clause.c
index b85fbebd00e..53a17ac3f6a 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -539,11 +539,11 @@ transformRangeFunction(ParseState *pstate, RangeFunction
*r)
!fc->func_variadic &&
coldeflist == NIL)
{
- ListCell *lc;
+ ListCell *lc2;
- foreach(lc, fc->args)
+ foreach(lc2, fc->args)
{
- Node *arg = (Node *) lfirst(lc);
+ Node *arg = (Node *) lfirst(lc2);
FuncCall *newfc;
last_srf = pstate->p_last_srf;
diff --git a/src/backend/statistics/dependencies.c
b/src/backend/statistics/dependencies.c
index c1c27e67d47..744bc512b65 100644
--- a/src/backend/statistics/dependencies.c
+++ b/src/backend/statistics/dependencies.c
@@ -1265,7 +1265,6 @@ dependency_is_compatible_expression(Node *clause, Index
relid, List *statlist, N
else if (is_orclause(clause))
{
BoolExpr *bool_expr = (BoolExpr *) clause;
- ListCell *lc;
/* start with no expression (we'll use the first match) */
*expr = NULL;
@@ -1693,7 +1692,6 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
{
int idx;
Node *expr;
- int k;
AttrNumber unique_attnum =
InvalidAttrNumber;
AttrNumber attnum;
@@ -1741,15 +1739,15 @@ dependencies_clauselist_selectivity(PlannerInfo *root,
expr = (Node *) list_nth(stat->exprs,
idx);
/* try to find the expression in the
unique list */
- for (k = 0; k < unique_exprs_cnt; k++)
+ for (int m = 0; m < unique_exprs_cnt;
m++)
{
/*
* found a matching unique
expression, use the attnum
* (derived from index of the
unique expression)
*/
- if (equal(unique_exprs[k],
expr))
+ if (equal(unique_exprs[m],
expr))
{
- unique_attnum = -(k +
1) + attnum_offset;
+ unique_attnum = -(m +
1) + attnum_offset;
break;
}
}
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 5410a68bc91..91b9635dc0a 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1604,7 +1604,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
Bitmapset *keys, List *exprs,
MCVList *mcvlist, bool is_or)
{
- int i;
ListCell *l;
bool *matches;
@@ -1659,7 +1658,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* can skip items that were already ruled out, and
terminate if
* there are no remaining MCV items that might possibly
match.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
{
bool match = true;
MCVItem *item = &mcvlist->items[i];
@@ -1766,7 +1765,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* can skip items that were already ruled out, and
terminate if
* there are no remaining MCV items that might possibly
match.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
{
int j;
bool match = !expr->useOr;
@@ -1837,7 +1836,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* can skip items that were already ruled out, and
terminate if
* there are no remaining MCV items that might possibly
match.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
{
bool match = false; /* assume
mismatch */
MCVItem *item = &mcvlist->items[i];
@@ -1862,7 +1861,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
{
/* AND/OR clause, with all subclauses being compatible
*/
- int i;
BoolExpr *bool_clause = ((BoolExpr *) clause);
List *bool_clauses = bool_clause->args;
@@ -1881,7 +1879,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* current one. We need to consider if we're evaluating
AND or OR
* condition when merging the results.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
matches[i] = RESULT_MERGE(matches[i], is_or,
bool_matches[i]);
pfree(bool_matches);
@@ -1890,7 +1888,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
{
/* NOT clause, with all subclauses compatible */
- int i;
BoolExpr *not_clause = ((BoolExpr *) clause);
List *not_args = not_clause->args;
@@ -1909,7 +1906,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* current one. We're handling a NOT clause, so invert
the result
* before merging it into the global bitmap.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
matches[i] = RESULT_MERGE(matches[i], is_or,
!not_matches[i]);
pfree(not_matches);
@@ -1930,7 +1927,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* can skip items that were already ruled out, and
terminate if
* there are no remaining MCV items that might possibly
match.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
{
MCVItem *item = &mcvlist->items[i];
bool match = false;
@@ -1956,7 +1953,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
* can skip items that were already ruled out, and
terminate if
* there are no remaining MCV items that might possibly
match.
*/
- for (i = 0; i < mcvlist->nitems; i++)
+ for (int i = 0; i < mcvlist->nitems; i++)
{
bool match;
MCVItem *item = &mcvlist->items[i];
diff --git a/src/backend/storage/buffer/bufmgr.c
b/src/backend/storage/buffer/bufmgr.c
index 7a1202c6096..49d3b8c9dd0 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -3183,7 +3183,6 @@ void
DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
{
int i;
- int j;
int n = 0;
SMgrRelation *rels;
BlockNumber (*block)[MAX_FORKNUM + 1];
@@ -3232,7 +3231,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int
nlocators)
*/
for (i = 0; i < n && cached; i++)
{
- for (j = 0; j <= MAX_FORKNUM; j++)
+ for (int j = 0; j <= MAX_FORKNUM; j++)
{
/* Get the number of blocks for a relation's fork. */
block[i][j] = smgrnblocks_cached(rels[i], j);
@@ -3259,7 +3258,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int
nlocators)
{
for (i = 0; i < n; i++)
{
- for (j = 0; j <= MAX_FORKNUM; j++)
+ for (int j = 0; j <= MAX_FORKNUM; j++)
{
/* ignore relation forks that doesn't exist */
if (!BlockNumberIsValid(block[i][j]))
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 6b0a8652622..ba9a568389f 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1087,6 +1087,23 @@ standard_ProcessUtility(PlannedStmt *pstmt,
CommandCounterIncrement();
}
+static ObjectAddress
+TryExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
+ ParamListInfo params, QueryCompletion
*qc)
+{
+ ObjectAddress address;
+ PG_TRY();
+ {
+ address = ExecRefreshMatView(stmt, queryString, params, qc);
+ }
+ PG_FINALLY();
+ {
+ EventTriggerUndoInhibitCommandCollection();
+ }
+ PG_END_TRY();
+ return address;
+}
+
/*
* The "Slow" variant of ProcessUtility should only receive statements
* supported by the event triggers facility. Therefore, we always
@@ -1678,16 +1695,10 @@ ProcessUtilitySlow(ParseState *pstate,
* command itself is queued, which is enough.
*/
EventTriggerInhibitCommandCollection();
- PG_TRY();
- {
- address =
ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
-
queryString, params, qc);
- }
- PG_FINALLY();
- {
-
EventTriggerUndoInhibitCommandCollection();
- }
- PG_END_TRY();
+
+ address =
TryExecRefreshMatView((RefreshMatViewStmt *) parsetree,
+
queryString, params, qc);
+
break;
case T_CreateTrigStmt:
diff --git a/src/backend/utils/adt/levenshtein.c
b/src/backend/utils/adt/levenshtein.c
index 3026cc24311..2e67a90e516 100644
--- a/src/backend/utils/adt/levenshtein.c
+++ b/src/backend/utils/adt/levenshtein.c
@@ -193,16 +193,16 @@ varstr_levenshtein(const char *source, int slen,
*/
if (m != slen || n != tlen)
{
- int i;
+ int k;
const char *cp = source;
s_char_len = (int *) palloc((m + 1) * sizeof(int));
- for (i = 0; i < m; ++i)
+ for (k = 0; k < m; ++k)
{
- s_char_len[i] = pg_mblen(cp);
- cp += s_char_len[i];
+ s_char_len[k] = pg_mblen(cp);
+ cp += s_char_len[k];
}
- s_char_len[i] = 0;
+ s_char_len[k] = 0;
}
/* One more cell for initialization column and row. */
diff --git a/src/backend/utils/adt/ruleutils.c
b/src/backend/utils/adt/ruleutils.c
index 8964f73b929..3f5683f70b5 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1303,7 +1303,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
if (!heap_attisnull(ht_idx, Anum_pg_index_indexprs, NULL))
{
Datum exprsDatum;
- bool isnull;
char *exprsString;
exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
@@ -1500,7 +1499,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
{
Node *node;
Datum predDatum;
- bool isnull;
char *predString;
/* Convert text string to node tree */
@@ -1648,7 +1646,6 @@ pg_get_statisticsobj_worker(Oid statextid, bool
columns_only, bool missing_ok)
if (has_exprs)
{
Datum exprsDatum;
- bool isnull;
char *exprsString;
exprsDatum = SysCacheGetAttr(STATEXTOID, statexttup,
@@ -1944,7 +1941,6 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
if (!heap_attisnull(tuple, Anum_pg_partitioned_table_partexprs, NULL))
{
Datum exprsDatum;
- bool isnull;
char *exprsString;
exprsDatum = SysCacheGetAttr(PARTRELID, tuple,
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2c689157329..c0d09edf9d0 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -11576,7 +11576,6 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
char **configitems = NULL;
int nconfigitems = 0;
const char *keyword;
- int i;
/* Do nothing in data-only dump */
if (dopt->dataOnly)
@@ -11776,11 +11775,10 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
if (*protrftypes)
{
Oid *typeids = palloc(FUNC_MAX_ARGS *
sizeof(Oid));
- int i;
appendPQExpBufferStr(q, " TRANSFORM ");
parseOidArray(protrftypes, typeids, FUNC_MAX_ARGS);
- for (i = 0; typeids[i]; i++)
+ for (int i = 0; typeids[i]; i++)
{
if (i != 0)
appendPQExpBufferStr(q, ", ");
@@ -11853,7 +11851,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
finfo->dobj.name);
}
- for (i = 0; i < nconfigitems; i++)
+ for (int i = 0; i < nconfigitems; i++)
{
/* we feel free to scribble on configitems[] here */
char *configitem = configitems[i];
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c
b/src/interfaces/ecpg/pgtypeslib/numeric.c
index a97b3300cb8..b666c909084 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -1062,7 +1062,6 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric
*result)
int weight_tmp;
int rscale_tmp;
int ri;
- int i;
long guess;
long first_have;
long first_div;
@@ -1109,7 +1108,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric
*result)
* Initialize local variables
*/
init_var(÷nd);
- for (i = 1; i < 10; i++)
+ for (int i = 1; i < 10; i++)
init_var(&divisor[i]);
/*
@@ -1181,7 +1180,6 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric
*result)
{
if (divisor[guess].buf == NULL)
{
- int i;
long sum = 0;
memcpy(&divisor[guess], &divisor[1],
sizeof(numeric));
@@ -1189,7 +1187,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric
*result)
if (divisor[guess].buf == NULL)
goto done;
divisor[guess].digits = divisor[guess].buf;
- for (i = divisor[1].ndigits - 1; i >= 0; i--)
+ for (int i = divisor[1].ndigits - 1; i >= 0;
i--)
{
sum += divisor[1].digits[i] * guess;
divisor[guess].digits[i] = sum % 10;
@@ -1268,7 +1266,7 @@ done:
if (dividend.buf != NULL)
digitbuf_free(dividend.buf);
- for (i = 1; i < 10; i++)
+ for (int i = 1; i < 10; i++)
{
if (divisor[i].buf != NULL)
digitbuf_free(divisor[i].buf);
diff --git a/src/pl/plpgsql/src/pl_funcs.c b/src/pl/plpgsql/src/pl_funcs.c
index 93d9cef06ba..7e6169fc203 100644
--- a/src/pl/plpgsql/src/pl_funcs.c
+++ b/src/pl/plpgsql/src/pl_funcs.c
@@ -1597,14 +1597,13 @@ dump_expr(PLpgSQL_expr *expr)
void
plpgsql_dumptree(PLpgSQL_function *func)
{
- int i;
PLpgSQL_datum *d;
printf("\nExecution tree of successfully compiled PL/pgSQL function
%s:\n",
func->fn_signature);
printf("\nFunction's data area:\n");
- for (i = 0; i < func->ndatums; i++)
+ for (int i = 0; i < func->ndatums; i++)
{
d = func->datums[i];
@@ -1647,13 +1646,12 @@ plpgsql_dumptree(PLpgSQL_function *func)
case PLPGSQL_DTYPE_ROW:
{
PLpgSQL_row *row = (PLpgSQL_row *) d;
- int i;
printf("ROW %-16s fields",
row->refname);
- for (i = 0; i < row->nfields; i++)
+ for (int j = 0; j < row->nfields; j++)
{
- printf(" %s=var %d",
row->fieldnames[i],
- row->varnos[i]);
+ printf(" %s=var %d",
row->fieldnames[j],
+ row->varnos[j]);
}
printf("\n");
}