Skip to content

Commit f4e7971

Browse files
committed
Change pgstat_report_vacuum() to use Relation
This change makes pgstat_report_vacuum() more consistent with pgstat_report_analyze(), that also uses a Relation. This enforces a policy that callers of this routine should open and lock the relation whose statistics are updated before calling this routine. We will unlikely have a lot of callers of this routine in the tree, but it seems like a good idea to imply this requirement in the long run. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Suggested-by: Andres Freund <andres@anarazel.de> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/aUEA6UZZkDCQFgSA@ip-10-97-1-34.eu-west-3.compute.internal
1 parent 1d325ad commit f4e7971

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/backend/access/heap/vacuumlazy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,8 +961,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params,
961961
* soon in cases where the failsafe prevented significant amounts of heap
962962
* vacuuming.
963963
*/
964-
pgstat_report_vacuum(RelationGetRelid(rel),
965-
rel->rd_rel->relisshared,
964+
pgstat_report_vacuum(rel,
966965
Max(vacrel->new_live_tuples, 0),
967966
vacrel->recently_dead_tuples +
968967
vacrel->missed_dead_tuples,

src/backend/utils/activity/pgstat_relation.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,13 @@ pgstat_drop_relation(Relation rel)
207207
* Report that the table was just vacuumed and flush IO statistics.
208208
*/
209209
void
210-
pgstat_report_vacuum(Oid tableoid, bool shared,
211-
PgStat_Counter livetuples, PgStat_Counter deadtuples,
212-
TimestampTz starttime)
210+
pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
211+
PgStat_Counter deadtuples, TimestampTz starttime)
213212
{
214213
PgStat_EntryRef *entry_ref;
215214
PgStatShared_Relation *shtabentry;
216215
PgStat_StatTabEntry *tabentry;
217-
Oid dboid = (shared ? InvalidOid : MyDatabaseId);
216+
Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
218217
TimestampTz ts;
219218
PgStat_Counter elapsedtime;
220219

@@ -226,8 +225,8 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
226225
elapsedtime = TimestampDifferenceMilliseconds(starttime, ts);
227226

228227
/* block acquiring lock for the same reason as pgstat_report_autovac() */
229-
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION,
230-
dboid, tableoid, false);
228+
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_RELATION, dboid,
229+
RelationGetRelid(rel), false);
231230

232231
shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
233232
tabentry = &shtabentry->stats;

src/include/pgstat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ extern void pgstat_init_relation(Relation rel);
669669
extern void pgstat_assoc_relation(Relation rel);
670670
extern void pgstat_unlink_relation(Relation rel);
671671

672-
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
673-
PgStat_Counter livetuples, PgStat_Counter deadtuples,
672+
extern void pgstat_report_vacuum(Relation rel, PgStat_Counter livetuples,
673+
PgStat_Counter deadtuples,
674674
TimestampTz starttime);
675675
extern void pgstat_report_analyze(Relation rel,
676676
PgStat_Counter livetuples, PgStat_Counter deadtuples,

0 commit comments

Comments
 (0)