From 97d12b434f53f2c00ee94cde41ccf76a8ef4d19e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 27 May 2007 17:28:36 +0000 Subject: [PATCH] Ooops, I was too busy worrying about getting the transactional infrastructure right to think carefully about how insert and delete counts map to n_live_tuples. Of course a deletion should reduce n_live_tuples. --- src/backend/postmaster/pgstat.c | 13 +++++++++---- src/include/pgstat.h | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 2870d33585..e23a665cd2 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.157 2007/05/27 05:37:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.158 2007/05/27 17:28:35 tgl Exp $ * ---------- */ #include "postgres.h" @@ -1376,7 +1376,8 @@ AtEOXact_PgStat(bool isCommit) Assert(tabstat->trans == trans); if (isCommit) { - tabstat->t_counts.t_new_live_tuples += trans->tuples_inserted; + tabstat->t_counts.t_new_live_tuples += + trans->tuples_inserted - trans->tuples_deleted; tabstat->t_counts.t_new_dead_tuples += trans->tuples_deleted; } else @@ -1563,7 +1564,8 @@ pgstat_twophase_postcommit(TransactionId xid, uint16 info, /* Find or create a tabstat entry for the rel */ pgstat_info = get_tabstat_entry(rec->t_id, rec->t_shared); - pgstat_info->t_counts.t_new_live_tuples += rec->tuples_inserted; + pgstat_info->t_counts.t_new_live_tuples += + rec->tuples_inserted - rec->tuples_deleted; pgstat_info->t_counts.t_new_dead_tuples += rec->tuples_deleted; } @@ -2919,6 +2921,9 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len) tabentry->blocks_hit += tabmsg[i].t_counts.t_blocks_hit; } + /* Clamp n_live_tuples in case of negative new_live_tuples */ + tabentry->n_live_tuples = Max(tabentry->n_live_tuples, 0); + /* * Add per-table stats to the per-database entry, too. */ @@ -3113,7 +3118,7 @@ pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len) } else { - /* last_anl_tuples must never exceed n_live_tuples */ + /* last_anl_tuples must never exceed n_live_tuples+n_dead_tuples */ tabentry->last_anl_tuples = Min(tabentry->last_anl_tuples, msg->m_tuples); } diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 02010c7d89..ff050e6e45 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -5,7 +5,7 @@ * * Copyright (c) 2001-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.60 2007/05/27 05:37:50 tgl Exp $ + * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.61 2007/05/27 17:28:36 tgl Exp $ * ---------- */ #ifndef PGSTAT_H @@ -58,6 +58,7 @@ typedef int64 PgStat_Counter; * tuples_inserted/tuples_updated/tuples_deleted count attempted actions, * regardless of whether the transaction committed. new_live_tuples and * new_dead_tuples are properly adjusted depending on commit or abort. + * Note that new_live_tuples can be negative! * ---------- */ typedef struct PgStat_TableCounts