Skip to content

Commit 83a1a1b

Browse files
committed
Generate pg_stat_get*() functions for tables using macros
The same code pattern is repeated 17 times for int64 counters (0 for missing entry) and 5 times for timestamps (NULL for missing entry) on table entries. This code is switched to use a macro for the basic code instead, shaving a few hundred lines of originally-duplicated code. The function names remain the same, but some fields of PgStat_StatTabEntry have to be renamed to cope with the new style. Author: Bertrand Drouvot Reviewed-by: Nathan Bossart Discussion: https:/postgr.es/m/20221204173207.GA2669116@nathanxps13
1 parent 941aa6a commit 83a1a1b

File tree

5 files changed

+139
-396
lines changed

5 files changed

+139
-396
lines changed

src/backend/access/heap/README.HOT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ physical tuple by eliminating an intermediate heap-only tuple or
271271
replacing a physical root tuple by a redirect pointer, a decrement in
272272
the table's number of dead tuples is reported to pgstats, which may
273273
postpone autovacuuming. Note that we do not count replacing a root tuple
274-
by a DEAD line pointer as decrementing n_dead_tuples; we still want
274+
by a DEAD line pointer as decrementing dead_tuples; we still want
275275
autovacuum to run to clean up the index entries and DEAD item.
276276

277277
This area probably needs further work ...

src/backend/postmaster/autovacuum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,9 +3081,9 @@ relation_needs_vacanalyze(Oid relid,
30813081
if (PointerIsValid(tabentry) && AutoVacuumingActive())
30823082
{
30833083
reltuples = classForm->reltuples;
3084-
vactuples = tabentry->n_dead_tuples;
3085-
instuples = tabentry->inserts_since_vacuum;
3086-
anltuples = tabentry->changes_since_analyze;
3084+
vactuples = tabentry->dead_tuples;
3085+
instuples = tabentry->ins_since_vacuum;
3086+
anltuples = tabentry->mod_since_analyze;
30873087

30883088
/* If the table hasn't yet been vacuumed, take reltuples as zero */
30893089
if (reltuples < 0)

src/backend/utils/activity/pgstat_relation.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
231231
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
232232
tabentry = &shtabentry->stats;
233233

234-
tabentry->n_live_tuples = livetuples;
235-
tabentry->n_dead_tuples = deadtuples;
234+
tabentry->live_tuples = livetuples;
235+
tabentry->dead_tuples = deadtuples;
236236

237237
/*
238238
* It is quite possible that a non-aggressive VACUUM ended up skipping
@@ -244,16 +244,16 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
244244
* autovacuum. An anti-wraparound autovacuum will catch any persistent
245245
* stragglers.
246246
*/
247-
tabentry->inserts_since_vacuum = 0;
247+
tabentry->ins_since_vacuum = 0;
248248

249249
if (IsAutoVacuumWorkerProcess())
250250
{
251-
tabentry->autovac_vacuum_timestamp = ts;
252-
tabentry->autovac_vacuum_count++;
251+
tabentry->last_autovacuum_time = ts;
252+
tabentry->autovacuum_count++;
253253
}
254254
else
255255
{
256-
tabentry->vacuum_timestamp = ts;
256+
tabentry->last_vacuum_time = ts;
257257
tabentry->vacuum_count++;
258258
}
259259

@@ -264,7 +264,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
264264
* Report that the table was just analyzed.
265265
*
266266
* Caller must provide new live- and dead-tuples estimates, as well as a
267-
* flag indicating whether to reset the changes_since_analyze counter.
267+
* flag indicating whether to reset the mod_since_analyze counter.
268268
*/
269269
void
270270
pgstat_report_analyze(Relation rel,
@@ -318,25 +318,25 @@ pgstat_report_analyze(Relation rel,
318318
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
319319
tabentry = &shtabentry->stats;
320320

321-
tabentry->n_live_tuples = livetuples;
322-
tabentry->n_dead_tuples = deadtuples;
321+
tabentry->live_tuples = livetuples;
322+
tabentry->dead_tuples = deadtuples;
323323

324324
/*
325-
* If commanded, reset changes_since_analyze to zero. This forgets any
325+
* If commanded, reset mod_since_analyze to zero. This forgets any
326326
* changes that were committed while the ANALYZE was in progress, but we
327327
* have no good way to estimate how many of those there were.
328328
*/
329329
if (resetcounter)
330-
tabentry->changes_since_analyze = 0;
330+
tabentry->mod_since_analyze = 0;
331331

332332
if (IsAutoVacuumWorkerProcess())
333333
{
334-
tabentry->autovac_analyze_timestamp = GetCurrentTimestamp();
335-
tabentry->autovac_analyze_count++;
334+
tabentry->last_autoanalyze_time = GetCurrentTimestamp();
335+
tabentry->autoanalyze_count++;
336336
}
337337
else
338338
{
339-
tabentry->analyze_timestamp = GetCurrentTimestamp();
339+
tabentry->last_analyze_time = GetCurrentTimestamp();
340340
tabentry->analyze_count++;
341341
}
342342

@@ -798,22 +798,22 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
798798
*/
799799
if (lstats->t_counts.t_truncdropped)
800800
{
801-
tabentry->n_live_tuples = 0;
802-
tabentry->n_dead_tuples = 0;
803-
tabentry->inserts_since_vacuum = 0;
801+
tabentry->live_tuples = 0;
802+
tabentry->dead_tuples = 0;
803+
tabentry->ins_since_vacuum = 0;
804804
}
805805

806-
tabentry->n_live_tuples += lstats->t_counts.t_delta_live_tuples;
807-
tabentry->n_dead_tuples += lstats->t_counts.t_delta_dead_tuples;
808-
tabentry->changes_since_analyze += lstats->t_counts.t_changed_tuples;
809-
tabentry->inserts_since_vacuum += lstats->t_counts.t_tuples_inserted;
806+
tabentry->live_tuples += lstats->t_counts.t_delta_live_tuples;
807+
tabentry->dead_tuples += lstats->t_counts.t_delta_dead_tuples;
808+
tabentry->mod_since_analyze += lstats->t_counts.t_changed_tuples;
809+
tabentry->ins_since_vacuum += lstats->t_counts.t_tuples_inserted;
810810
tabentry->blocks_fetched += lstats->t_counts.t_blocks_fetched;
811811
tabentry->blocks_hit += lstats->t_counts.t_blocks_hit;
812812

813-
/* Clamp n_live_tuples in case of negative delta_live_tuples */
814-
tabentry->n_live_tuples = Max(tabentry->n_live_tuples, 0);
815-
/* Likewise for n_dead_tuples */
816-
tabentry->n_dead_tuples = Max(tabentry->n_dead_tuples, 0);
813+
/* Clamp live_tuples in case of negative delta_live_tuples */
814+
tabentry->live_tuples = Max(tabentry->live_tuples, 0);
815+
/* Likewise for dead_tuples */
816+
tabentry->dead_tuples = Max(tabentry->dead_tuples, 0);
817817

818818
pgstat_unlock_entry(entry_ref);
819819

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy