summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorBernd Helmle2010-09-21 20:42:54 +0000
committerBernd Helmle2010-09-21 20:42:54 +0000
commited626abcec5fdeb09795d3e7fe2280f4b0642ebc (patch)
treeb9aa68e8bd6bbe6f41a4bb2b12f7f937dd835b60 /src/backend
parenteacc4a3b9a7ea8a2608cb95981646f947efed625 (diff)
Merge truncate stats patch into new branch.truncate_stats
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/system_views.sql1
-rw-r--r--src/backend/commands/tablecmds.c5
-rw-r--r--src/backend/postmaster/pgstat.c68
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c15
4 files changed, 67 insertions, 22 deletions
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 651ffc61b9..ce9a7f729c 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -196,6 +196,7 @@ CREATE VIEW pg_stat_all_tables AS
pg_stat_get_tuples_updated(C.oid) AS n_tup_upd,
pg_stat_get_tuples_deleted(C.oid) AS n_tup_del,
pg_stat_get_tuples_hot_updated(C.oid) AS n_tup_hot_upd,
+ pg_stat_get_numtruncate(C.oid) AS n_truncate,
pg_stat_get_live_tuples(C.oid) AS n_live_tup,
pg_stat_get_dead_tuples(C.oid) AS n_dead_tup,
pg_stat_get_last_vacuum_time(C.oid) as last_vacuum,
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 82143682d5..ab657a0d4e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -1064,6 +1064,11 @@ ExecuteTruncate(TruncateStmt *stmt)
{
Relation rel = (Relation) lfirst(cell);
+ /*
+ * increase statistic counts
+ */
+ pgstat_count_heap_truncate(rel);
+
heap_close(rel, NoLock);
}
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 483d7afe34..edd1aceb0f 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -1736,6 +1736,27 @@ pgstat_update_heap_dead_tuples(Relation rel, int delta)
pgstat_info->t_counts.t_delta_dead_tuples -= delta;
}
+/*
+ * pgstat_count_heap_truncate - count heap truncate operations
+ */
+void
+pgstat_count_heap_truncate(Relation rel)
+{
+ PgStat_TableStatus *pgstat_info = rel->pgstat_info;
+
+ if (pgstat_track_counts && pgstat_info != NULL)
+ {
+ int nest_level = GetCurrentTransactionNestLevel();
+ pgstat_info->t_counts.t_numtruncate++;
+
+ /* We have to log the transactional effect at the proper level */
+ if (pgstat_info->trans == NULL ||
+ pgstat_info->trans->nest_level != nest_level)
+ add_tabstat_xact_level(pgstat_info, nest_level);
+
+ pgstat_info->trans->trunc_state.numtruncate++;
+ }
+}
/* ----------
* AtEOXact_PgStat
@@ -3850,18 +3871,20 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
* If it's a new table entry, initialize counters to the values we
* just got.
*/
- tabentry->numscans = tabmsg->t_counts.t_numscans;
- tabentry->tuples_returned = tabmsg->t_counts.t_tuples_returned;
- tabentry->tuples_fetched = tabmsg->t_counts.t_tuples_fetched;
- tabentry->tuples_inserted = tabmsg->t_counts.t_tuples_inserted;
- tabentry->tuples_updated = tabmsg->t_counts.t_tuples_updated;
- tabentry->tuples_deleted = tabmsg->t_counts.t_tuples_deleted;
- tabentry->tuples_hot_updated = tabmsg->t_counts.t_tuples_hot_updated;
- tabentry->n_live_tuples = tabmsg->t_counts.t_delta_live_tuples;
- tabentry->n_dead_tuples = tabmsg->t_counts.t_delta_dead_tuples;
+<<<<<<< HEAD
+ tabentry->numscans = tabmsg[i].t_counts.t_numscans;
+ tabentry->tuples_returned = tabmsg[i].t_counts.t_tuples_returned;
+ tabentry->tuples_fetched = tabmsg[i].t_counts.t_tuples_fetched;
+ tabentry->tuples_inserted = tabmsg[i].t_counts.t_tuples_inserted;
+ tabentry->tuples_updated = tabmsg[i].t_counts.t_tuples_updated;
+ tabentry->tuples_deleted = tabmsg[i].t_counts.t_tuples_deleted;
+ tabentry->tuples_hot_updated = tabmsg[i].t_counts.t_tuples_hot_updated;
+ tabentry->numtruncate = tabmsg[i].t_counts.t_numtruncate;
+ tabentry->n_live_tuples = tabmsg[i].t_counts.t_new_live_tuples;
+ tabentry->n_dead_tuples = tabmsg[i].t_counts.t_new_dead_tuples;
tabentry->changes_since_analyze = tabmsg->t_counts.t_changed_tuples;
- tabentry->blocks_fetched = tabmsg->t_counts.t_blocks_fetched;
- tabentry->blocks_hit = tabmsg->t_counts.t_blocks_hit;
+ tabentry->blocks_fetched = tabmsg[i].t_counts.t_blocks_fetched;
+ tabentry->blocks_hit = tabmsg[i].t_counts.t_blocks_hit;
tabentry->vacuum_timestamp = 0;
tabentry->autovac_vacuum_timestamp = 0;
@@ -3873,18 +3896,19 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
/*
* Otherwise add the values to the existing entry.
*/
- tabentry->numscans += tabmsg->t_counts.t_numscans;
- tabentry->tuples_returned += tabmsg->t_counts.t_tuples_returned;
- tabentry->tuples_fetched += tabmsg->t_counts.t_tuples_fetched;
- tabentry->tuples_inserted += tabmsg->t_counts.t_tuples_inserted;
- tabentry->tuples_updated += tabmsg->t_counts.t_tuples_updated;
- tabentry->tuples_deleted += tabmsg->t_counts.t_tuples_deleted;
- tabentry->tuples_hot_updated += tabmsg->t_counts.t_tuples_hot_updated;
- tabentry->n_live_tuples += tabmsg->t_counts.t_delta_live_tuples;
- tabentry->n_dead_tuples += tabmsg->t_counts.t_delta_dead_tuples;
+ tabentry->numscans += tabmsg[i].t_counts.t_numscans;
+ tabentry->tuples_returned += tabmsg[i].t_counts.t_tuples_returned;
+ tabentry->tuples_fetched += tabmsg[i].t_counts.t_tuples_fetched;
+ tabentry->tuples_inserted += tabmsg[i].t_counts.t_tuples_inserted;
+ tabentry->tuples_updated += tabmsg[i].t_counts.t_tuples_updated;
+ tabentry->tuples_deleted += tabmsg[i].t_counts.t_tuples_deleted;
+ tabentry->tuples_hot_updated += tabmsg[i].t_counts.t_tuples_hot_updated;
+ tabentry->numtruncate += tabmsg[i].t_counts.t_numtruncate;
+ tabentry->n_live_tuples += tabmsg[i].t_counts.t_new_live_tuples;
+ tabentry->n_dead_tuples += tabmsg[i].t_counts.t_new_dead_tuples;
tabentry->changes_since_analyze += tabmsg->t_counts.t_changed_tuples;
- tabentry->blocks_fetched += tabmsg->t_counts.t_blocks_fetched;
- tabentry->blocks_hit += tabmsg->t_counts.t_blocks_hit;
+ tabentry->blocks_fetched += tabmsg[i].t_counts.t_blocks_fetched;
+ tabentry->blocks_hit += tabmsg[i].t_counts.t_blocks_hit;
}
/* Clamp n_live_tuples in case of negative delta_live_tuples */
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6edb8bfd13..c4011a74dd 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -29,6 +29,7 @@ extern Datum pg_stat_get_tuples_fetched(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_tuples_inserted(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_tuples_updated(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_numtruncate(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_live_tuples(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_dead_tuples(PG_FUNCTION_ARGS);
@@ -198,6 +199,20 @@ pg_stat_get_tuples_deleted(PG_FUNCTION_ARGS)
PG_RETURN_INT64(result);
}
+Datum
+pg_stat_get_numtruncate(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ int64 result;
+ PgStat_StatTabEntry *tabentry;
+
+ if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL)
+ result = 0;
+ else
+ result = (int64) (tabentry->numtruncate);
+
+ PG_RETURN_INT64(result);
+}
Datum
pg_stat_get_tuples_hot_updated(PG_FUNCTION_ARGS)