diff options
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/access/gist/gistget.c | 6 | ||||
| -rw-r--r-- | src/backend/access/hash/hashsearch.c | 5 | ||||
| -rw-r--r-- | src/backend/access/heap/heapam.c | 29 | ||||
| -rw-r--r-- | src/backend/access/index/indexam.c | 17 | ||||
| -rw-r--r-- | src/backend/access/nbtree/nbtsearch.c | 5 | ||||
| -rw-r--r-- | src/backend/access/rtree/rtget.c | 5 | ||||
| -rw-r--r-- | src/backend/catalog/system_views.sql | 13 | ||||
| -rw-r--r-- | src/backend/executor/nodeBitmapHeapscan.c | 13 | ||||
| -rw-r--r-- | src/backend/postmaster/pgstat.c | 8 |
9 files changed, 57 insertions, 44 deletions
diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c index f63bc477ae..5ae48bd66e 100644 --- a/src/backend/access/gist/gistget.c +++ b/src/backend/access/gist/gistget.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.51 2005/09/22 20:44:36 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gist/gistget.c,v 1.52 2005/10/06 02:29:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,8 +17,10 @@ #include "access/itup.h" #include "access/gist_private.h" #include "executor/execdebug.h" +#include "pgstat.h" #include "utils/memutils.h" + static OffsetNumber gistfindnext(IndexScanDesc scan, OffsetNumber n, ScanDirection dir); static int gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, bool ignore_killed_tuples); @@ -161,6 +163,8 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b stk->next = NULL; stk->block = GIST_ROOT_BLKNO; + + pgstat_count_index_scan(&scan->xs_pgstat_info); } else if (so->curbuf == InvalidBuffer) { diff --git a/src/backend/access/hash/hashsearch.c b/src/backend/access/hash/hashsearch.c index 3bef169412..9aaf70b0a9 100644 --- a/src/backend/access/hash/hashsearch.c +++ b/src/backend/access/hash/hashsearch.c @@ -8,13 +8,14 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.38 2004/12/31 21:59:13 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.39 2005/10/06 02:29:08 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres.h" #include "access/hash.h" +#include "pgstat.h" #include "storage/lmgr.h" @@ -130,6 +131,8 @@ _hash_first(IndexScanDesc scan, ScanDirection dir) ItemPointer current; OffsetNumber offnum; + pgstat_count_index_scan(&scan->xs_pgstat_info); + current = &(scan->currentItemData); ItemPointerSetInvalid(current); diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 46c7c4da73..185918d03a 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.198 2005/08/20 00:39:51 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.199 2005/10/06 02:29:10 tgl Exp $ * * * INTERFACE ROUTINES @@ -47,10 +47,10 @@ #include "catalog/catalog.h" #include "catalog/namespace.h" #include "miscadmin.h" +#include "pgstat.h" #include "storage/procarray.h" #include "utils/inval.h" #include "utils/relcache.h" -#include "pgstat.h" static XLogRecPtr log_heap_update(Relation reln, Buffer oldbuf, @@ -90,6 +90,8 @@ initscan(HeapScanDesc scan, ScanKey key) */ if (key != NULL) memcpy(scan->rs_key, key, scan->rs_nkeys * sizeof(ScanKeyData)); + + pgstat_count_heap_scan(&scan->rs_pgstat_info); } /* ---------------- @@ -680,8 +682,6 @@ heap_rescan(HeapScanDesc scan, * reinitialize scan descriptor */ initscan(scan, key); - - pgstat_reset_heap_scan(&scan->rs_pgstat_info); } /* ---------------- @@ -762,8 +762,6 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction) return NULL; } - pgstat_count_heap_scan(&scan->rs_pgstat_info); - /* * if we get here it means we have a new current scan tuple, so point * to the proper return buffer and return the tuple. @@ -927,14 +925,9 @@ heap_release_fetch(Relation relation, */ *userbuf = buffer; - /* - * Count the successful fetch in *pgstat_info if given, otherwise - * in the relation's default statistics area. - */ + /* Count the successful fetch in *pgstat_info, if given. */ if (pgstat_info != NULL) pgstat_count_heap_fetch(pgstat_info); - else - pgstat_count_heap_fetch(&relation->pgstat_info); return true; } @@ -1152,8 +1145,6 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid, RelationPutHeapTuple(relation, buffer, tup); - pgstat_count_heap_insert(&relation->pgstat_info); - /* XLOG stuff */ if (relation->rd_istemp) { @@ -1229,6 +1220,8 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid, */ CacheInvalidateHeapTuple(relation, tup); + pgstat_count_heap_insert(&relation->pgstat_info); + return HeapTupleGetOid(tup); } @@ -1481,8 +1474,6 @@ l1: if (HeapTupleHasExternal(&tp)) heap_tuple_toast_attrs(relation, NULL, &tp); - pgstat_count_heap_delete(&relation->pgstat_info); - /* * Mark tuple for invalidation from system caches at next command * boundary. We have to do this before WriteBuffer because we need to @@ -1499,6 +1490,8 @@ l1: if (have_tuple_lock) UnlockTuple(relation, &(tp.t_self), ExclusiveLock); + pgstat_count_heap_delete(&relation->pgstat_info); + return HeapTupleMayBeUpdated; } @@ -1851,8 +1844,6 @@ l2: newbuf = buffer; } - pgstat_count_heap_update(&relation->pgstat_info); - /* * At this point newbuf and buffer are both pinned and locked, and * newbuf has enough space for the new tuple. If they are the same @@ -1929,6 +1920,8 @@ l2: if (have_tuple_lock) UnlockTuple(relation, &(oldtup.t_self), ExclusiveLock); + pgstat_count_heap_update(&relation->pgstat_info); + return HeapTupleMayBeUpdated; } diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index 624b53d635..7bf7fcd22f 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.84 2005/06/27 12:45:22 teodor Exp $ + * $PostgreSQL: pgsql/src/backend/access/index/indexam.c,v 1.85 2005/10/06 02:29:11 tgl Exp $ * * INTERFACE ROUTINES * index_open - open an index relation by relation OID @@ -65,9 +65,9 @@ #include "access/genam.h" #include "access/heapam.h" +#include "pgstat.h" #include "utils/relcache.h" -#include "pgstat.h" /* ---------------------------------------------------------------- * macros used in index_ routines @@ -354,8 +354,6 @@ index_rescan(IndexScanDesc scan, ScanKey key) FunctionCall2(procedure, PointerGetDatum(scan), PointerGetDatum(key)); - - pgstat_reset_index_scan(&scan->xs_pgstat_info); } /* ---------------- @@ -521,8 +519,6 @@ index_getnext(IndexScanDesc scan, ScanDirection direction) { bool found; - pgstat_count_index_scan(&scan->xs_pgstat_info); - /* * The AM's gettuple proc finds the next tuple matching the scan * keys. @@ -545,6 +541,8 @@ index_getnext(IndexScanDesc scan, ScanDirection direction) return NULL; /* failure exit */ } + pgstat_count_index_tuples(&scan->xs_pgstat_info, 1); + /* * Fetch the heap tuple and see if it matches the snapshot. */ @@ -583,8 +581,6 @@ index_getnext(IndexScanDesc scan, ScanDirection direction) * initialized to 0, which is the correct state ("on row"). */ - pgstat_count_index_getnext(&scan->xs_pgstat_info); - return heapTuple; } @@ -621,6 +617,9 @@ index_getnext_indexitem(IndexScanDesc scan, PointerGetDatum(scan), Int32GetDatum(direction))); + if (found) + pgstat_count_index_tuples(&scan->xs_pgstat_info, 1); + return found; } @@ -660,6 +659,8 @@ index_getmulti(IndexScanDesc scan, Int32GetDatum(max_tids), PointerGetDatum(returned_tids))); + pgstat_count_index_tuples(&scan->xs_pgstat_info, *returned_tids); + return found; } diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 42bd6574aa..c029824fa6 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.93 2005/06/19 22:41:00 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.94 2005/10/06 02:29:12 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,6 +17,7 @@ #include "access/genam.h" #include "access/nbtree.h" +#include "pgstat.h" #include "utils/lsyscache.h" @@ -501,6 +502,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir) int i; StrategyNumber strat_total; + pgstat_count_index_scan(&scan->xs_pgstat_info); + /* * Examine the scan keys and eliminate any redundant keys; also * discover how many keys must be matched to continue the scan. diff --git a/src/backend/access/rtree/rtget.c b/src/backend/access/rtree/rtget.c index e076d5a989..199a178c4f 100644 --- a/src/backend/access/rtree/rtget.c +++ b/src/backend/access/rtree/rtget.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/rtree/rtget.c,v 1.35 2005/03/27 23:53:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/rtree/rtget.c,v 1.36 2005/10/06 02:29:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,6 +18,8 @@ #include "access/iqual.h" #include "access/relscan.h" #include "access/rtree.h" +#include "pgstat.h" + static OffsetNumber findnext(IndexScanDesc s, OffsetNumber n, ScanDirection dir); @@ -118,6 +120,7 @@ rtnext(IndexScanDesc s, ScanDirection dir) /* first call: start at the root */ Assert(BufferIsValid(so->curbuf) == false); so->curbuf = ReadBuffer(s->indexRelation, P_ROOT); + pgstat_count_index_scan(&s->xs_pgstat_info); } p = BufferGetPage(so->curbuf); diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 10826e21f7..4ffb8ac2c5 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -3,7 +3,7 @@ * * Copyright (c) 1996-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.21 2005/08/15 23:00:13 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.22 2005/10/06 02:29:15 tgl Exp $ */ CREATE VIEW pg_roles AS @@ -182,8 +182,9 @@ CREATE VIEW pg_stat_all_tables AS C.relname AS relname, pg_stat_get_numscans(C.oid) AS seq_scan, pg_stat_get_tuples_returned(C.oid) AS seq_tup_read, - sum(pg_stat_get_numscans(I.indexrelid)) AS idx_scan, - sum(pg_stat_get_tuples_fetched(I.indexrelid)) AS idx_tup_fetch, + sum(pg_stat_get_numscans(I.indexrelid))::bigint AS idx_scan, + sum(pg_stat_get_tuples_fetched(I.indexrelid))::bigint + + pg_stat_get_tuples_fetched(C.oid) AS idx_tup_fetch, pg_stat_get_tuples_inserted(C.oid) AS n_tup_ins, pg_stat_get_tuples_updated(C.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(C.oid) AS n_tup_del @@ -210,8 +211,8 @@ CREATE VIEW pg_statio_all_tables AS pg_stat_get_blocks_hit(C.oid) AS heap_blks_read, pg_stat_get_blocks_hit(C.oid) AS heap_blks_hit, sum(pg_stat_get_blocks_fetched(I.indexrelid) - - pg_stat_get_blocks_hit(I.indexrelid)) AS idx_blks_read, - sum(pg_stat_get_blocks_hit(I.indexrelid)) AS idx_blks_hit, + pg_stat_get_blocks_hit(I.indexrelid))::bigint AS idx_blks_read, + sum(pg_stat_get_blocks_hit(I.indexrelid))::bigint AS idx_blks_hit, pg_stat_get_blocks_fetched(T.oid) - pg_stat_get_blocks_hit(T.oid) AS toast_blks_read, pg_stat_get_blocks_hit(T.oid) AS toast_blks_hit, @@ -350,5 +351,5 @@ UPDATE pg_proc SET 'bool'], proargmodes = ARRAY['i'::"char", 'o', 'o', 'o', 'o', 'o', 'o'], proargnames = ARRAY['filename'::text, 'size', 'access', 'modification', - 'change', 'creation', 'isdir'] + 'change', 'creation', 'isdir'] WHERE oid = 'pg_stat_file(text)'::regprocedure; diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c index 16d9bf0611..3c3c1fd96f 100644 --- a/src/backend/executor/nodeBitmapHeapscan.c +++ b/src/backend/executor/nodeBitmapHeapscan.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.2 2005/05/06 17:24:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeBitmapHeapscan.c,v 1.3 2005/10/06 02:29:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -39,6 +39,7 @@ #include "executor/execdebug.h" #include "executor/nodeBitmapHeapscan.h" #include "parser/parsetree.h" +#include "pgstat.h" #include "utils/memutils.h" @@ -328,6 +329,9 @@ ExecBitmapHeapReScan(BitmapHeapScanState *node, ExprContext *exprCtxt) /* rescan to release any page pin */ heap_rescan(node->ss.ss_currentScanDesc, NULL); + /* undo bogus "seq scan" count (see notes in ExecInitBitmapHeapScan) */ + pgstat_discount_heap_scan(&node->ss.ss_currentScanDesc->rs_pgstat_info); + if (node->tbm) tbm_free(node->tbm); node->tbm = NULL; @@ -476,6 +480,13 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate) NULL); /* + * One problem is that heap_beginscan counts a "sequential scan" start, + * when we actually aren't doing any such thing. Reverse out the added + * scan count. (Eventually we may want to count bitmap scans separately.) + */ + pgstat_discount_heap_scan(&scanstate->ss.ss_currentScanDesc->rs_pgstat_info); + + /* * get the scan type from the relation descriptor. */ ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation), false); diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index e53b8a8c92..d03f812476 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.108 2005/09/24 17:53:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.109 2005/10/06 02:29:17 tgl Exp $ * ---------- */ #include "postgres.h" @@ -1159,17 +1159,11 @@ pgstat_initstats(PgStat_Info *stats, Relation rel) * Initialize data not to count at all. */ stats->tabentry = NULL; - stats->no_stats = FALSE; - stats->heap_scan_counted = FALSE; - stats->index_scan_counted = FALSE; if (pgStatSock < 0 || !(pgstat_collect_tuplelevel || pgstat_collect_blocklevel)) - { - stats->no_stats = TRUE; return; - } tsarr = rel->rd_rel->relisshared ? &SharedTabStat : &RegularTabStat; |
