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)
100100 if (key != NULL )
101101 memcpy (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)
701701 if (!RelationIsValid (r ))
702702 elog (ERROR , "could not open relation with OID %u" , relationId );
703703
704+ pgstat_initstats (r );
705+
704706 return r ;
705707}
706708
@@ -743,6 +745,8 @@ try_relation_open(Oid relationId, LOCKMODE lockmode)
743745 if (!RelationIsValid (r ))
744746 elog (ERROR , "could not open relation with OID %u" , relationId );
745747
748+ pgstat_initstats (r );
749+
746750 return r ;
747751}
748752
@@ -787,6 +791,8 @@ relation_open_nowait(Oid relationId, LOCKMODE lockmode)
787791 if (!RelationIsValid (r ))
788792 elog (ERROR , "could not open relation with OID %u" , relationId );
789793
794+ pgstat_initstats (r );
795+
790796 return r ;
791797}
792798
@@ -873,8 +879,6 @@ heap_open(Oid relationId, LOCKMODE lockmode)
873879 errmsg ("\"%s\" is a composite type" ,
874880 RelationGetRelationName (r ))));
875881
876- pgstat_initstats (& r -> pgstat_info , r );
877-
878882 return r ;
879883}
880884
@@ -903,8 +907,6 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
903907 errmsg ("\"%s\" is a composite type" ,
904908 RelationGetRelationName (r ))));
905909
906- pgstat_initstats (& r -> pgstat_info , r );
907-
908910 return r ;
909911}
910912
@@ -954,8 +956,6 @@ heap_beginscan(Relation relation, Snapshot snapshot,
954956 else
955957 scan -> rs_key = NULL ;
956958
957- pgstat_initstats (& scan -> rs_pgstat_info , relation );
958-
959959 initscan (scan , key );
960960
961961 return scan ;
@@ -1059,7 +1059,7 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
10591059 */
10601060 HEAPDEBUG_3 ; /* heap_getnext returning tuple */
10611061
1062- pgstat_count_heap_getnext (& scan -> rs_pgstat_info );
1062+ pgstat_count_heap_getnext (scan -> rs_rd );
10631063
10641064 return & (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,
11011105 HeapTuple tuple ,
11021106 Buffer * userbuf ,
11031107 bool keep_buf ,
1104- PgStat_Info * pgstat_info )
1108+ Relation stats_relation )
11051109{
11061110 /* Assume *userbuf is undefined on entry */
11071111 * userbuf = InvalidBuffer ;
11081112 return 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,
11251129 HeapTuple tuple ,
11261130 Buffer * userbuf ,
11271131 bool keep_buf ,
1128- PgStat_Info * pgstat_info )
1132+ Relation stats_relation )
11291133{
11301134 ItemPointer tid = & (tuple -> t_self );
11311135 ItemId lp ;
@@ -1210,9 +1214,9 @@ heap_release_fetch(Relation relation,
12101214 */
12111215 * userbuf = buffer ;
12121216
1213- /* Count the successful fetch in *pgstat_info , if given. */
1214- if (pgstat_info != NULL )
1215- pgstat_count_heap_fetch (pgstat_info );
1217+ /* Count the successful fetch against appropriate rel , if any */
1218+ if (stats_relation != NULL )
1219+ pgstat_count_heap_fetch (stats_relation );
12161220
12171221 return true;
12181222 }
@@ -1517,7 +1521,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
15171521 */
15181522 CacheInvalidateHeapTuple (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,
18071811 if (have_tuple_lock )
18081812 UnlockTuple (relation , & (tp .t_self ), ExclusiveLock );
18091813
1810- pgstat_count_heap_delete (& relation -> pgstat_info );
1814+ pgstat_count_heap_delete (relation );
18111815
18121816 return HeapTupleMayBeUpdated ;
18131817}
@@ -2269,7 +2273,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
22692273 if (have_tuple_lock )
22702274 UnlockTuple (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
0 commit comments