*
* 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"
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
/* 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;
}
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.
*/
}
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);
}
*
* 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
* 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