pgstat: fix small bug in pgstat_drop_relation().

Just after committing 5891c7a8ed8, a test running with debug_discard_caches=1
failed locally...

pgstat_drop_relation() neither checked pgstat_should_count_relation() nor
called pgstat_prep_relation_pending(). With debug_discard_caches=1
rel->pgstat_info wasn't set up, leading pg_stat_get_xact_tuples_inserted()
spuriously still returning > 0 while in the transaction dropping the table.
This commit is contained in:
Andres Freund 2022-04-06 23:35:56 -07:00
parent 81ae9e6588
commit 5e07d3d6bd

View File

@ -180,18 +180,21 @@ void
pgstat_drop_relation(Relation rel)
{
int nest_level = GetCurrentTransactionNestLevel();
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
PgStat_TableStatus *pgstat_info;
pgstat_drop_transactional(PGSTAT_KIND_RELATION,
rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
RelationGetRelid(rel));
if (!pgstat_should_count_relation(rel))
return;
/*
* Transactionally set counters to 0. That ensures that accesses to
* pg_stat_xact_all_tables inside the transaction show 0.
*/
if (pgstat_info &&
pgstat_info->trans != NULL &&
pgstat_info = rel->pgstat_info;
if (pgstat_info->trans &&
pgstat_info->trans->nest_level == nest_level)
{
save_truncdrop_counters(pgstat_info->trans, true);