Skip to content

Navigation Menu

Sign in
Appearance settings

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 3d51cb5

Browse filesBrowse files
Rename some support functions for pgstat* views.
Presently, pgstat_fetch_stat_beentry() accepts a session's backend ID as its argument, and pgstat_fetch_stat_local_beentry() accepts a 1-based index in an internal array as its argument. The former is typically used wherever a user must provide a backend ID, and the latter is usually used internally when looping over all entries in the array. This difference was first introduced by d7e39d7. Before that commit, both functions accepted a 1-based index to the internal array. This commit renames these two functions to make it clear whether they use the backend ID or the 1-based index to look up the entry. This is preparatory work for a follow-up change that will introduce a function for looking up a LocalPgBackendStatus using a backend ID. Reviewed-by: Ian Barwick, Sami Imseih, Michael Paquier, Robert Haas Discussion: https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.com Backpatch-through: 16
1 parent fe39f43 commit 3d51cb5
Copy full SHA for 3d51cb5

File tree

Expand file treeCollapse file tree

3 files changed

+34
-34
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+34
-34
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/utils/activity/backend_status.c
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ pgstat_read_current_status(void)
849849
/*
850850
* The BackendStatusArray index is exactly the BackendId of the
851851
* source backend. Note that this means localBackendStatusTable
852-
* is in order by backend_id. pgstat_fetch_stat_beentry() depends
853-
* on that.
852+
* is in order by backend_id. pgstat_get_beentry_by_backend_id()
853+
* depends on that.
854854
*/
855855
localentry->backend_id = i;
856856
BackendIdGetTransactionIds(i,
@@ -1073,21 +1073,21 @@ cmp_lbestatus(const void *a, const void *b)
10731073
}
10741074

10751075
/* ----------
1076-
* pgstat_fetch_stat_beentry() -
1076+
* pgstat_get_beentry_by_backend_id() -
10771077
*
10781078
* Support function for the SQL-callable pgstat* functions. Returns
10791079
* our local copy of the current-activity entry for one backend,
10801080
* or NULL if the given beid doesn't identify any known session.
10811081
*
10821082
* The beid argument is the BackendId of the desired session
1083-
* (note that this is unlike pgstat_fetch_stat_local_beentry()).
1083+
* (note that this is unlike pgstat_get_local_beentry_by_index()).
10841084
*
10851085
* NB: caller is responsible for a check if the user is permitted to see
10861086
* this info (especially the querystring).
10871087
* ----------
10881088
*/
10891089
PgBackendStatus *
1090-
pgstat_fetch_stat_beentry(BackendId beid)
1090+
pgstat_get_beentry_by_backend_id(BackendId beid)
10911091
{
10921092
LocalPgBackendStatus key;
10931093
LocalPgBackendStatus *ret;
@@ -1111,28 +1111,28 @@ pgstat_fetch_stat_beentry(BackendId beid)
11111111

11121112

11131113
/* ----------
1114-
* pgstat_fetch_stat_local_beentry() -
1114+
* pgstat_get_local_beentry_by_index() -
11151115
*
1116-
* Like pgstat_fetch_stat_beentry() but with locally computed additions (like
1117-
* xid and xmin values of the backend)
1116+
* Like pgstat_get_beentry_by_backend_id() but with locally computed additions
1117+
* (like xid and xmin values of the backend)
11181118
*
1119-
* The beid argument is a 1-based index in the localBackendStatusTable
1120-
* (note that this is unlike pgstat_fetch_stat_beentry()).
1119+
* The idx argument is a 1-based index in the localBackendStatusTable
1120+
* (note that this is unlike pgstat_get_beentry_by_backend_id()).
11211121
* Returns NULL if the argument is out of range (no current caller does that).
11221122
*
11231123
* NB: caller is responsible for a check if the user is permitted to see
11241124
* this info (especially the querystring).
11251125
* ----------
11261126
*/
11271127
LocalPgBackendStatus *
1128-
pgstat_fetch_stat_local_beentry(int beid)
1128+
pgstat_get_local_beentry_by_index(int idx)
11291129
{
11301130
pgstat_read_current_status();
11311131

1132-
if (beid < 1 || beid > localNumBackends)
1132+
if (idx < 1 || idx > localNumBackends)
11331133
return NULL;
11341134

1135-
return &localBackendStatusTable[beid - 1];
1135+
return &localBackendStatusTable[idx - 1];
11361136
}
11371137

11381138

@@ -1141,7 +1141,7 @@ pgstat_fetch_stat_local_beentry(int beid)
11411141
*
11421142
* Support function for the SQL-callable pgstat* functions. Returns
11431143
* the number of sessions known in the localBackendStatusTable, i.e.
1144-
* the maximum 1-based index to pass to pgstat_fetch_stat_local_beentry().
1144+
* the maximum 1-based index to pass to pgstat_get_local_beentry_by_index().
11451145
* ----------
11461146
*/
11471147
int

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/pgstatfuncs.c
+18-18Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
211211
if (fctx[0] <= pgstat_fetch_stat_numbackends())
212212
{
213213
/* do when there is more left to send */
214-
LocalPgBackendStatus *local_beentry = pgstat_fetch_stat_local_beentry(fctx[0]);
214+
LocalPgBackendStatus *local_beentry = pgstat_get_local_beentry_by_index(fctx[0]);
215215

216216
SRF_RETURN_NEXT(funcctx, Int32GetDatum(local_beentry->backend_id));
217217
}
@@ -264,7 +264,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
264264
bool nulls[PG_STAT_GET_PROGRESS_COLS] = {0};
265265
int i;
266266

267-
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
267+
local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
268268
beentry = &local_beentry->backendStatus;
269269

270270
/*
@@ -325,7 +325,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
325325
const char *wait_event = NULL;
326326

327327
/* Get the next one in the list */
328-
local_beentry = pgstat_fetch_stat_local_beentry(curr_backend);
328+
local_beentry = pgstat_get_local_beentry_by_index(curr_backend);
329329
beentry = &local_beentry->backendStatus;
330330

331331
/* If looking for specific PID, ignore all the others */
@@ -672,7 +672,7 @@ pg_stat_get_backend_pid(PG_FUNCTION_ARGS)
672672
int32 beid = PG_GETARG_INT32(0);
673673
PgBackendStatus *beentry;
674674

675-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
675+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
676676
PG_RETURN_NULL();
677677

678678
PG_RETURN_INT32(beentry->st_procpid);
@@ -685,7 +685,7 @@ pg_stat_get_backend_dbid(PG_FUNCTION_ARGS)
685685
int32 beid = PG_GETARG_INT32(0);
686686
PgBackendStatus *beentry;
687687

688-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
688+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
689689
PG_RETURN_NULL();
690690

691691
PG_RETURN_OID(beentry->st_databaseid);
@@ -698,7 +698,7 @@ pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
698698
int32 beid = PG_GETARG_INT32(0);
699699
PgBackendStatus *beentry;
700700

701-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
701+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
702702
PG_RETURN_NULL();
703703

704704
PG_RETURN_OID(beentry->st_userid);
@@ -727,7 +727,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
727727

728728
BlessTupleDesc(tupdesc);
729729

730-
if ((local_beentry = pgstat_fetch_stat_local_beentry(beid)) != NULL)
730+
if ((local_beentry = pgstat_get_local_beentry_by_index(beid)) != NULL)
731731
{
732732
/* Fill values and NULLs */
733733
values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
@@ -752,7 +752,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
752752
char *clipped_activity;
753753
text *ret;
754754

755-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
755+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
756756
activity = "<backend information not available>";
757757
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
758758
activity = "<insufficient privilege>";
@@ -776,7 +776,7 @@ pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
776776
PGPROC *proc;
777777
const char *wait_event_type = NULL;
778778

779-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
779+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
780780
wait_event_type = "<backend information not available>";
781781
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
782782
wait_event_type = "<insufficient privilege>";
@@ -797,7 +797,7 @@ pg_stat_get_backend_wait_event(PG_FUNCTION_ARGS)
797797
PGPROC *proc;
798798
const char *wait_event = NULL;
799799

800-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
800+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
801801
wait_event = "<backend information not available>";
802802
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
803803
wait_event = "<insufficient privilege>";
@@ -818,7 +818,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
818818
TimestampTz result;
819819
PgBackendStatus *beentry;
820820

821-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
821+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
822822
PG_RETURN_NULL();
823823

824824
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -844,7 +844,7 @@ pg_stat_get_backend_xact_start(PG_FUNCTION_ARGS)
844844
TimestampTz result;
845845
PgBackendStatus *beentry;
846846

847-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
847+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
848848
PG_RETURN_NULL();
849849

850850
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -866,7 +866,7 @@ pg_stat_get_backend_start(PG_FUNCTION_ARGS)
866866
TimestampTz result;
867867
PgBackendStatus *beentry;
868868

869-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
869+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
870870
PG_RETURN_NULL();
871871

872872
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -890,7 +890,7 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
890890
char remote_host[NI_MAXHOST];
891891
int ret;
892892

893-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
893+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
894894
PG_RETURN_NULL();
895895

896896
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -935,7 +935,7 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
935935
char remote_port[NI_MAXSERV];
936936
int ret;
937937

938-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
938+
if ((beentry = pgstat_get_beentry_by_backend_id(beid)) == NULL)
939939
PG_RETURN_NULL();
940940

941941
else if (!HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
@@ -978,12 +978,12 @@ pg_stat_get_db_numbackends(PG_FUNCTION_ARGS)
978978
Oid dbid = PG_GETARG_OID(0);
979979
int32 result;
980980
int tot_backends = pgstat_fetch_stat_numbackends();
981-
int beid;
981+
int idx;
982982

983983
result = 0;
984-
for (beid = 1; beid <= tot_backends; beid++)
984+
for (idx = 1; idx <= tot_backends; idx++)
985985
{
986-
LocalPgBackendStatus *local_beentry = pgstat_fetch_stat_local_beentry(beid);
986+
LocalPgBackendStatus *local_beentry = pgstat_get_local_beentry_by_index(idx);
987987

988988
if (local_beentry->backendStatus.st_databaseid == dbid)
989989
result++;

‎src/include/utils/backend_status.h

Copy file name to clipboardExpand all lines: src/include/utils/backend_status.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ extern uint64 pgstat_get_my_query_id(void);
333333
* ----------
334334
*/
335335
extern int pgstat_fetch_stat_numbackends(void);
336-
extern PgBackendStatus *pgstat_fetch_stat_beentry(BackendId beid);
337-
extern LocalPgBackendStatus *pgstat_fetch_stat_local_beentry(int beid);
336+
extern PgBackendStatus *pgstat_get_beentry_by_backend_id(BackendId beid);
337+
extern LocalPgBackendStatus *pgstat_get_local_beentry_by_index(int idx);
338338
extern char *pgstat_clip_activity(const char *raw_activity);
339339

340340

0 commit comments

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