88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.232 2007/04/08 01:26:27 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.233 2007/05/27 03:50:38 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -100,7 +100,7 @@ initscan(HeapScanDesc scan, ScanKey key)
100100if (key != NULL )
101101memcpy (scan -> rs_key ,key ,scan -> rs_nkeys * sizeof (ScanKeyData ));
102102
103- pgstat_count_heap_scan (& scan -> rs_pgstat_info );
103+ pgstat_count_heap_scan (scan -> rs_rd );
104104}
105105
106106/*
@@ -701,6 +701,8 @@ relation_open(Oid relationId, LOCKMODE lockmode)
701701if (!RelationIsValid (r ))
702702elog (ERROR ,"could not open relation with OID %u" ,relationId );
703703
704+ pgstat_initstats (r );
705+
704706return r ;
705707}
706708
@@ -743,6 +745,8 @@ try_relation_open(Oid relationId, LOCKMODE lockmode)
743745if (!RelationIsValid (r ))
744746elog (ERROR ,"could not open relation with OID %u" ,relationId );
745747
748+ pgstat_initstats (r );
749+
746750return r ;
747751}
748752
@@ -787,6 +791,8 @@ relation_open_nowait(Oid relationId, LOCKMODE lockmode)
787791if (!RelationIsValid (r ))
788792elog (ERROR ,"could not open relation with OID %u" ,relationId );
789793
794+ pgstat_initstats (r );
795+
790796return r ;
791797}
792798
@@ -873,8 +879,6 @@ heap_open(Oid relationId, LOCKMODE lockmode)
873879errmsg ("\"%s\" is a composite type" ,
874880RelationGetRelationName (r ))));
875881
876- pgstat_initstats (& r -> pgstat_info ,r );
877-
878882return r ;
879883}
880884
@@ -903,8 +907,6 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
903907errmsg ("\"%s\" is a composite type" ,
904908RelationGetRelationName (r ))));
905909
906- pgstat_initstats (& r -> pgstat_info ,r );
907-
908910return r ;
909911}
910912
@@ -954,8 +956,6 @@ heap_beginscan(Relation relation, Snapshot snapshot,
954956else
955957scan -> rs_key = NULL ;
956958
957- pgstat_initstats (& scan -> rs_pgstat_info ,relation );
958-
959959initscan (scan ,key );
960960
961961return scan ;
@@ -1059,7 +1059,7 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
10591059 */
10601060HEAPDEBUG_3 ;/* heap_getnext returning tuple */
10611061
1062- pgstat_count_heap_getnext (& scan -> rs_pgstat_info );
1062+ pgstat_count_heap_getnext (scan -> rs_rd );
10631063
10641064return & (scan -> rs_ctup );
10651065}
@@ -1086,6 +1086,10 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
10861086 * and return it in *userbuf (so the caller must eventually unpin it); when
10871087 * keep_buf = false, the pin is released and *userbuf is set to InvalidBuffer.
10881088 *
1089+ * stats_relation is the relation to charge the heap_fetch operation against
1090+ * for statistical purposes. (This could be the heap rel itself, an
1091+ * associated index, or NULL to not count the fetch at all.)
1092+ *
10891093 * It is somewhat inconsistent that we ereport() on invalid block number but
10901094 * return false on invalid item number. There are a couple of reasons though.
10911095 * One is that the caller can relatively easily check the block number for
@@ -1101,12 +1105,12 @@ heap_fetch(Relation relation,
11011105HeapTuple tuple ,
11021106Buffer * userbuf ,
11031107bool keep_buf ,
1104- PgStat_Info * pgstat_info )
1108+ Relation stats_relation )
11051109{
11061110/* Assume *userbuf is undefined on entry */
11071111* userbuf = InvalidBuffer ;
11081112return heap_release_fetch (relation ,snapshot ,tuple ,
1109- userbuf ,keep_buf ,pgstat_info );
1113+ userbuf ,keep_buf ,stats_relation );
11101114}
11111115
11121116/*
@@ -1125,7 +1129,7 @@ heap_release_fetch(Relation relation,
11251129HeapTuple tuple ,
11261130Buffer * userbuf ,
11271131bool keep_buf ,
1128- PgStat_Info * pgstat_info )
1132+ Relation stats_relation )
11291133{
11301134ItemPointer tid = & (tuple -> t_self );
11311135ItemId lp ;
@@ -1210,9 +1214,9 @@ heap_release_fetch(Relation relation,
12101214 */
12111215* userbuf = buffer ;
12121216
1213- /* Count the successful fetchin *pgstat_info , ifgiven. */
1214- if (pgstat_info != NULL )
1215- pgstat_count_heap_fetch (pgstat_info );
1217+ /* Count the successful fetchagainst appropriate rel , ifany */
1218+ if (stats_relation != NULL )
1219+ pgstat_count_heap_fetch (stats_relation );
12161220
12171221return true;
12181222}
@@ -1517,7 +1521,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
15171521 */
15181522CacheInvalidateHeapTuple (relation ,heaptup );
15191523
1520- pgstat_count_heap_insert (& relation -> pgstat_info );
1524+ pgstat_count_heap_insert (relation );
15211525
15221526/*
15231527 * If heaptup is a private copy, release it. Don't forget to copy t_self
@@ -1807,7 +1811,7 @@ heap_delete(Relation relation, ItemPointer tid,
18071811if (have_tuple_lock )
18081812UnlockTuple (relation ,& (tp .t_self ),ExclusiveLock );
18091813
1810- pgstat_count_heap_delete (& relation -> pgstat_info );
1814+ pgstat_count_heap_delete (relation );
18111815
18121816return HeapTupleMayBeUpdated ;
18131817}
@@ -2269,7 +2273,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
22692273if (have_tuple_lock )
22702274UnlockTuple (relation ,& (oldtup .t_self ),ExclusiveLock );
22712275
2272- pgstat_count_heap_update (& relation -> pgstat_info );
2276+ pgstat_count_heap_update (relation );
22732277
22742278/*
22752279 * If heaptup is a private copy, release it. Don't forget to copy t_self