Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 728560d

Browse filesBrowse files
committed
Suppress compiler warnings in new pgstats code.
Some clang versions whine about comparing an enum variable to a value outside the range of the enum, on the grounds that the result must be constant. In the cases we fix here, the loops will terminate only if the enum variable can in fact hold a value one beyond its declared range. While that's very likely to always be true for these enum types, it still seems like a poor coding practice to assume it; so use "int" loop variables instead to silence the warnings. (This matches what we've done in other places, for example loops over the range of ForkNumber.) While at it, let's drop the XXX_FIRST macros for these enums and just write zeroes for the loop start values. The apparent flexibility seems rather illusory given that iterating up to one-less-than- the-number-of-values is only correct for a zero-based range. Melanie Plageman Discussion: https://postgr.es/m/20520.1677435600@sss.pgh.pa.us
1 parent 53fe7e6 commit 728560d
Copy full SHA for 728560d

File tree

3 files changed

+10
-20
lines changed
Filter options

3 files changed

+10
-20
lines changed

‎src/backend/utils/activity/pgstat_io.c

Copy file name to clipboardExpand all lines: src/backend/utils/activity/pgstat_io.c
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ pgstat_bktype_io_stats_valid(PgStat_BktypeIO *backend_io,
3636
{
3737
bool bktype_tracked = pgstat_tracks_io_bktype(bktype);
3838

39-
for (IOObject io_object = IOOBJECT_FIRST;
40-
io_object < IOOBJECT_NUM_TYPES; io_object++)
39+
for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
4140
{
42-
for (IOContext io_context = IOCONTEXT_FIRST;
43-
io_context < IOCONTEXT_NUM_TYPES; io_context++)
41+
for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
4442
{
4543
/*
4644
* Don't bother trying to skip to the next loop iteration if
4745
* pgstat_tracks_io_object() would return false here. We still
4846
* need to validate that each counter is zero anyway.
4947
*/
50-
for (IOOp io_op = IOOP_FIRST; io_op < IOOP_NUM_TYPES; io_op++)
48+
for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
5149
{
5250
/* No stats, so nothing to validate */
5351
if (backend_io->data[io_object][io_context][io_op] == 0)
@@ -111,14 +109,11 @@ pgstat_flush_io(bool nowait)
111109
else if (!LWLockConditionalAcquire(bktype_lock, LW_EXCLUSIVE))
112110
return true;
113111

114-
for (IOObject io_object = IOOBJECT_FIRST;
115-
io_object < IOOBJECT_NUM_TYPES; io_object++)
112+
for (int io_object = 0; io_object < IOOBJECT_NUM_TYPES; io_object++)
116113
{
117-
for (IOContext io_context = IOCONTEXT_FIRST;
118-
io_context < IOCONTEXT_NUM_TYPES; io_context++)
114+
for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
119115
{
120-
for (IOOp io_op = IOOP_FIRST;
121-
io_op < IOOP_NUM_TYPES; io_op++)
116+
for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
122117
bktype_shstats->data[io_object][io_context][io_op] +=
123118
PendingIOStats.data[io_object][io_context][io_op];
124119
}

‎src/backend/utils/adt/pgstatfuncs.c

Copy file name to clipboardExpand all lines: src/backend/utils/adt/pgstatfuncs.c
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
13061306

13071307
reset_time = TimestampTzGetDatum(backends_io_stats->stat_reset_timestamp);
13081308

1309-
for (BackendType bktype = B_INVALID; bktype < BACKEND_NUM_TYPES; bktype++)
1309+
for (int bktype = 0; bktype < BACKEND_NUM_TYPES; bktype++)
13101310
{
13111311
Datum bktype_desc = CStringGetTextDatum(GetBackendTypeDesc(bktype));
13121312
PgStat_BktypeIO *bktype_stats = &backends_io_stats->stats[bktype];
@@ -1325,13 +1325,11 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
13251325
if (!pgstat_tracks_io_bktype(bktype))
13261326
continue;
13271327

1328-
for (IOObject io_obj = IOOBJECT_FIRST;
1329-
io_obj < IOOBJECT_NUM_TYPES; io_obj++)
1328+
for (int io_obj = 0; io_obj < IOOBJECT_NUM_TYPES; io_obj++)
13301329
{
13311330
const char *obj_name = pgstat_get_io_object_name(io_obj);
13321331

1333-
for (IOContext io_context = IOCONTEXT_FIRST;
1334-
io_context < IOCONTEXT_NUM_TYPES; io_context++)
1332+
for (int io_context = 0; io_context < IOCONTEXT_NUM_TYPES; io_context++)
13351333
{
13361334
const char *context_name = pgstat_get_io_context_name(io_context);
13371335

@@ -1359,7 +1357,7 @@ pg_stat_get_io(PG_FUNCTION_ARGS)
13591357
*/
13601358
values[IO_COL_CONVERSION] = Int64GetDatum(BLCKSZ);
13611359

1362-
for (IOOp io_op = IOOP_FIRST; io_op < IOOP_NUM_TYPES; io_op++)
1360+
for (int io_op = 0; io_op < IOOP_NUM_TYPES; io_op++)
13631361
{
13641362
int col_idx = pgstat_get_io_op_index(io_op);
13651363

‎src/include/pgstat.h

Copy file name to clipboardExpand all lines: src/include/pgstat.h
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ typedef enum IOObject
287287
IOOBJECT_TEMP_RELATION,
288288
} IOObject;
289289

290-
#define IOOBJECT_FIRST IOOBJECT_RELATION
291290
#define IOOBJECT_NUM_TYPES (IOOBJECT_TEMP_RELATION + 1)
292291

293292
typedef enum IOContext
@@ -298,7 +297,6 @@ typedef enum IOContext
298297
IOCONTEXT_VACUUM,
299298
} IOContext;
300299

301-
#define IOCONTEXT_FIRST IOCONTEXT_BULKREAD
302300
#define IOCONTEXT_NUM_TYPES (IOCONTEXT_VACUUM + 1)
303301

304302
typedef enum IOOp
@@ -311,7 +309,6 @@ typedef enum IOOp
311309
IOOP_WRITE,
312310
} IOOp;
313311

314-
#define IOOP_FIRST IOOP_EVICT
315312
#define IOOP_NUM_TYPES (IOOP_WRITE + 1)
316313

317314
typedef struct PgStat_BktypeIO

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.