Skip to content

Commit 03f2bf7

Browse files
committed
Fix handling of pgstat counters for TRUNCATE in a prepared transaction.
pgstat_twophase_postcommit is supposed to duplicate the math in AtEOXact_PgStat, but it had missed out the bit about clearing t_delta_live_tuples/t_delta_dead_tuples for a TRUNCATE. It's harder than you might think to replicate the issue here, because those counters would only be nonzero when a previous transaction in the same backend had added/deleted tuples in the truncated table, and those counts hadn't been sent to the stats collector yet. Evident oversight in commit d42358e. I've not added a regression test for this; we tried to add one in d42358e, and had to revert it because it was too timing-sensitive for the buildfarm. Back-patch to 9.5 where d42358e came in. Stas Kelvich Discussion: <EB57BF68-C06D-4737-BDDC-4BA778F4E62B@postgrespro.ru>
1 parent b885003 commit 03f2bf7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,12 @@ pgstat_twophase_postcommit(TransactionId xid, uint16 info,
22212221
pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
22222222
pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
22232223
pgstat_info->t_counts.t_truncated = rec->t_truncated;
2224-
2224+
if (rec->t_truncated)
2225+
{
2226+
/* forget live/dead stats seen by backend thus far */
2227+
pgstat_info->t_counts.t_delta_live_tuples = 0;
2228+
pgstat_info->t_counts.t_delta_dead_tuples = 0;
2229+
}
22252230
pgstat_info->t_counts.t_delta_live_tuples +=
22262231
rec->tuples_inserted - rec->tuples_deleted;
22272232
pgstat_info->t_counts.t_delta_dead_tuples +=

0 commit comments

Comments
 (0)