mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
backend/nodes cleanup: Move loop variables definitions into for statement
Author: Chao Li (Evan) <lic@highgo.com> Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2nP12qwAaiJutbn1Kw50atN6FbMJNQ4bh4%2BfP_Ay_u7Eg%40mail.gmail.com
This commit is contained in:
@@ -538,7 +538,6 @@ bms_is_member(int x, const Bitmapset *a)
|
|||||||
int
|
int
|
||||||
bms_member_index(Bitmapset *a, int x)
|
bms_member_index(Bitmapset *a, int x)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int bitnum;
|
int bitnum;
|
||||||
int wordnum;
|
int wordnum;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@@ -554,7 +553,7 @@ bms_member_index(Bitmapset *a, int x)
|
|||||||
bitnum = BITNUM(x);
|
bitnum = BITNUM(x);
|
||||||
|
|
||||||
/* count bits in preceding words */
|
/* count bits in preceding words */
|
||||||
for (i = 0; i < wordnum; i++)
|
for (int i = 0; i < wordnum; i++)
|
||||||
{
|
{
|
||||||
bitmapword w = a->words[i];
|
bitmapword w = a->words[i];
|
||||||
|
|
||||||
@@ -1306,7 +1305,6 @@ int
|
|||||||
bms_next_member(const Bitmapset *a, int prevbit)
|
bms_next_member(const Bitmapset *a, int prevbit)
|
||||||
{
|
{
|
||||||
int nwords;
|
int nwords;
|
||||||
int wordnum;
|
|
||||||
bitmapword mask;
|
bitmapword mask;
|
||||||
|
|
||||||
Assert(bms_is_valid_set(a));
|
Assert(bms_is_valid_set(a));
|
||||||
@@ -1316,7 +1314,7 @@ bms_next_member(const Bitmapset *a, int prevbit)
|
|||||||
nwords = a->nwords;
|
nwords = a->nwords;
|
||||||
prevbit++;
|
prevbit++;
|
||||||
mask = (~(bitmapword) 0) << BITNUM(prevbit);
|
mask = (~(bitmapword) 0) << BITNUM(prevbit);
|
||||||
for (wordnum = WORDNUM(prevbit); wordnum < nwords; wordnum++)
|
for (int wordnum = WORDNUM(prevbit); wordnum < nwords; wordnum++)
|
||||||
{
|
{
|
||||||
bitmapword w = a->words[wordnum];
|
bitmapword w = a->words[wordnum];
|
||||||
|
|
||||||
@@ -1366,7 +1364,6 @@ bms_next_member(const Bitmapset *a, int prevbit)
|
|||||||
int
|
int
|
||||||
bms_prev_member(const Bitmapset *a, int prevbit)
|
bms_prev_member(const Bitmapset *a, int prevbit)
|
||||||
{
|
{
|
||||||
int wordnum;
|
|
||||||
int ushiftbits;
|
int ushiftbits;
|
||||||
bitmapword mask;
|
bitmapword mask;
|
||||||
|
|
||||||
@@ -1391,7 +1388,7 @@ bms_prev_member(const Bitmapset *a, int prevbit)
|
|||||||
|
|
||||||
ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(prevbit) + 1);
|
ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(prevbit) + 1);
|
||||||
mask = (~(bitmapword) 0) >> ushiftbits;
|
mask = (~(bitmapword) 0) >> ushiftbits;
|
||||||
for (wordnum = WORDNUM(prevbit); wordnum >= 0; wordnum--)
|
for (int wordnum = WORDNUM(prevbit); wordnum >= 0; wordnum--)
|
||||||
{
|
{
|
||||||
bitmapword w = a->words[wordnum];
|
bitmapword w = a->words[wordnum];
|
||||||
|
|
||||||
|
|||||||
@@ -4826,9 +4826,7 @@ planstate_walk_members(PlanState **planstates, int nplans,
|
|||||||
planstate_tree_walker_callback walker,
|
planstate_tree_walker_callback walker,
|
||||||
void *context)
|
void *context)
|
||||||
{
|
{
|
||||||
int j;
|
for (int j = 0; j < nplans; j++)
|
||||||
|
|
||||||
for (j = 0; j < nplans; j++)
|
|
||||||
{
|
{
|
||||||
if (PSWALK(planstates[j]))
|
if (PSWALK(planstates[j]))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -346,8 +346,7 @@ outBitmapset(StringInfo str, const Bitmapset *bms)
|
|||||||
void
|
void
|
||||||
outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
||||||
{
|
{
|
||||||
Size length,
|
Size length;
|
||||||
i;
|
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
length = datumGetSize(value, typbyval, typlen);
|
length = datumGetSize(value, typbyval, typlen);
|
||||||
@@ -356,7 +355,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
|||||||
{
|
{
|
||||||
s = (char *) (&value);
|
s = (char *) (&value);
|
||||||
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
||||||
for (i = 0; i < (Size) sizeof(Datum); i++)
|
for (Size i = 0; i < (Size) sizeof(Datum); i++)
|
||||||
appendStringInfo(str, "%d ", (int) (s[i]));
|
appendStringInfo(str, "%d ", (int) (s[i]));
|
||||||
appendStringInfoChar(str, ']');
|
appendStringInfoChar(str, ']');
|
||||||
}
|
}
|
||||||
@@ -368,7 +367,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
||||||
for (i = 0; i < length; i++)
|
for (Size i = 0; i < length; i++)
|
||||||
appendStringInfo(str, "%d ", (int) (s[i]));
|
appendStringInfo(str, "%d ", (int) (s[i]));
|
||||||
appendStringInfoChar(str, ']');
|
appendStringInfoChar(str, ']');
|
||||||
}
|
}
|
||||||
@@ -434,8 +433,6 @@ _outBoolExpr(StringInfo str, const BoolExpr *node)
|
|||||||
static void
|
static void
|
||||||
_outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
_outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
|
WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
|
||||||
|
|
||||||
WRITE_UINT_FIELD(con_relid);
|
WRITE_UINT_FIELD(con_relid);
|
||||||
@@ -450,10 +447,10 @@ _outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
|||||||
WRITE_INT_FIELD(nmatched_ri);
|
WRITE_INT_FIELD(nmatched_ri);
|
||||||
/* for compactness, just print the number of matches per column: */
|
/* for compactness, just print the number of matches per column: */
|
||||||
appendStringInfoString(str, " :eclass");
|
appendStringInfoString(str, " :eclass");
|
||||||
for (i = 0; i < node->nkeys; i++)
|
for (int i = 0; i < node->nkeys; i++)
|
||||||
appendStringInfo(str, " %d", (node->eclass[i] != NULL));
|
appendStringInfo(str, " %d", (node->eclass[i] != NULL));
|
||||||
appendStringInfoString(str, " :rinfos");
|
appendStringInfoString(str, " :rinfos");
|
||||||
for (i = 0; i < node->nkeys; i++)
|
for (int i = 0; i < node->nkeys; i++)
|
||||||
appendStringInfo(str, " %d", list_length(node->rinfos[i]));
|
appendStringInfo(str, " %d", list_length(node->rinfos[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,13 +166,12 @@ paramlist_param_ref(ParseState *pstate, ParamRef *pref)
|
|||||||
Size
|
Size
|
||||||
EstimateParamListSpace(ParamListInfo paramLI)
|
EstimateParamListSpace(ParamListInfo paramLI)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
Size sz = sizeof(int);
|
Size sz = sizeof(int);
|
||||||
|
|
||||||
if (paramLI == NULL || paramLI->numParams <= 0)
|
if (paramLI == NULL || paramLI->numParams <= 0)
|
||||||
return sz;
|
return sz;
|
||||||
|
|
||||||
for (i = 0; i < paramLI->numParams; i++)
|
for (int i = 0; i < paramLI->numParams; i++)
|
||||||
{
|
{
|
||||||
ParamExternData *prm;
|
ParamExternData *prm;
|
||||||
ParamExternData prmdata;
|
ParamExternData prmdata;
|
||||||
@@ -229,7 +228,6 @@ void
|
|||||||
SerializeParamList(ParamListInfo paramLI, char **start_address)
|
SerializeParamList(ParamListInfo paramLI, char **start_address)
|
||||||
{
|
{
|
||||||
int nparams;
|
int nparams;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Write number of parameters. */
|
/* Write number of parameters. */
|
||||||
if (paramLI == NULL || paramLI->numParams <= 0)
|
if (paramLI == NULL || paramLI->numParams <= 0)
|
||||||
@@ -240,7 +238,7 @@ SerializeParamList(ParamListInfo paramLI, char **start_address)
|
|||||||
*start_address += sizeof(int);
|
*start_address += sizeof(int);
|
||||||
|
|
||||||
/* Write each parameter in turn. */
|
/* Write each parameter in turn. */
|
||||||
for (i = 0; i < nparams; i++)
|
for (int i = 0; i < nparams; i++)
|
||||||
{
|
{
|
||||||
ParamExternData *prm;
|
ParamExternData *prm;
|
||||||
ParamExternData prmdata;
|
ParamExternData prmdata;
|
||||||
|
|||||||
@@ -599,8 +599,7 @@ parseNodeString(void)
|
|||||||
Datum
|
Datum
|
||||||
readDatum(bool typbyval)
|
readDatum(bool typbyval)
|
||||||
{
|
{
|
||||||
Size length,
|
Size length;
|
||||||
i;
|
|
||||||
int tokenLength;
|
int tokenLength;
|
||||||
const char *token;
|
const char *token;
|
||||||
Datum res;
|
Datum res;
|
||||||
@@ -623,7 +622,7 @@ readDatum(bool typbyval)
|
|||||||
elog(ERROR, "byval datum but length = %zu", length);
|
elog(ERROR, "byval datum but length = %zu", length);
|
||||||
res = (Datum) 0;
|
res = (Datum) 0;
|
||||||
s = (char *) (&res);
|
s = (char *) (&res);
|
||||||
for (i = 0; i < (Size) sizeof(Datum); i++)
|
for (Size i = 0; i < (Size) sizeof(Datum); i++)
|
||||||
{
|
{
|
||||||
token = pg_strtok(&tokenLength);
|
token = pg_strtok(&tokenLength);
|
||||||
s[i] = (char) atoi(token);
|
s[i] = (char) atoi(token);
|
||||||
@@ -634,7 +633,7 @@ readDatum(bool typbyval)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
s = (char *) palloc(length);
|
s = (char *) palloc(length);
|
||||||
for (i = 0; i < length; i++)
|
for (Size i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
token = pg_strtok(&tokenLength);
|
token = pg_strtok(&tokenLength);
|
||||||
s[i] = (char) atoi(token);
|
s[i] = (char) atoi(token);
|
||||||
|
|||||||
@@ -369,10 +369,9 @@ tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids,
|
|||||||
{
|
{
|
||||||
BlockNumber currblk = InvalidBlockNumber;
|
BlockNumber currblk = InvalidBlockNumber;
|
||||||
PagetableEntry *page = NULL; /* only valid when currblk is valid */
|
PagetableEntry *page = NULL; /* only valid when currblk is valid */
|
||||||
int i;
|
|
||||||
|
|
||||||
Assert(tbm->iterating == TBM_NOT_ITERATING);
|
Assert(tbm->iterating == TBM_NOT_ITERATING);
|
||||||
for (i = 0; i < ntids; i++)
|
for (int i = 0; i < ntids; i++)
|
||||||
{
|
{
|
||||||
BlockNumber blk = ItemPointerGetBlockNumber(tids + i);
|
BlockNumber blk = ItemPointerGetBlockNumber(tids + i);
|
||||||
OffsetNumber off = ItemPointerGetOffsetNumber(tids + i);
|
OffsetNumber off = ItemPointerGetOffsetNumber(tids + i);
|
||||||
@@ -471,12 +470,11 @@ static void
|
|||||||
tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
|
tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
|
||||||
{
|
{
|
||||||
PagetableEntry *apage;
|
PagetableEntry *apage;
|
||||||
int wordnum;
|
|
||||||
|
|
||||||
if (bpage->ischunk)
|
if (bpage->ischunk)
|
||||||
{
|
{
|
||||||
/* Scan b's chunk, mark each indicated page lossy in a */
|
/* Scan b's chunk, mark each indicated page lossy in a */
|
||||||
for (wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
|
for (int wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
|
||||||
{
|
{
|
||||||
bitmapword w = bpage->words[wordnum];
|
bitmapword w = bpage->words[wordnum];
|
||||||
|
|
||||||
@@ -511,7 +509,7 @@ tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Both pages are exact, merge at the bit level */
|
/* Both pages are exact, merge at the bit level */
|
||||||
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
||||||
apage->words[wordnum] |= bpage->words[wordnum];
|
apage->words[wordnum] |= bpage->words[wordnum];
|
||||||
apage->recheck |= bpage->recheck;
|
apage->recheck |= bpage->recheck;
|
||||||
}
|
}
|
||||||
@@ -579,14 +577,13 @@ static bool
|
|||||||
tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
|
tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
|
||||||
{
|
{
|
||||||
const PagetableEntry *bpage;
|
const PagetableEntry *bpage;
|
||||||
int wordnum;
|
|
||||||
|
|
||||||
if (apage->ischunk)
|
if (apage->ischunk)
|
||||||
{
|
{
|
||||||
/* Scan each bit in chunk, try to clear */
|
/* Scan each bit in chunk, try to clear */
|
||||||
bool candelete = true;
|
bool candelete = true;
|
||||||
|
|
||||||
for (wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
|
for (int wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
|
||||||
{
|
{
|
||||||
bitmapword w = apage->words[wordnum];
|
bitmapword w = apage->words[wordnum];
|
||||||
|
|
||||||
@@ -640,7 +637,7 @@ tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
|
|||||||
{
|
{
|
||||||
/* Both pages are exact, merge at the bit level */
|
/* Both pages are exact, merge at the bit level */
|
||||||
Assert(!bpage->ischunk);
|
Assert(!bpage->ischunk);
|
||||||
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
||||||
{
|
{
|
||||||
apage->words[wordnum] &= bpage->words[wordnum];
|
apage->words[wordnum] &= bpage->words[wordnum];
|
||||||
if (apage->words[wordnum] != 0)
|
if (apage->words[wordnum] != 0)
|
||||||
@@ -904,10 +901,9 @@ tbm_extract_page_tuple(TBMIterateResult *iteritem,
|
|||||||
uint32 max_offsets)
|
uint32 max_offsets)
|
||||||
{
|
{
|
||||||
PagetableEntry *page = iteritem->internal_page;
|
PagetableEntry *page = iteritem->internal_page;
|
||||||
int wordnum;
|
|
||||||
int ntuples = 0;
|
int ntuples = 0;
|
||||||
|
|
||||||
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
|
||||||
{
|
{
|
||||||
bitmapword w = page->words[wordnum];
|
bitmapword w = page->words[wordnum];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user