8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -100,7 +100,7 @@ initscan(HeapScanDesc scan, ScanKey key)
100
100
if (key != NULL )
101
101
memcpy (scan -> rs_key , key , scan -> rs_nkeys * sizeof (ScanKeyData ));
102
102
103
- pgstat_count_heap_scan (& scan -> rs_pgstat_info );
103
+ pgstat_count_heap_scan (scan -> rs_rd );
104
104
}
105
105
106
106
/*
@@ -701,6 +701,8 @@ relation_open(Oid relationId, LOCKMODE lockmode)
701
701
if (!RelationIsValid (r ))
702
702
elog (ERROR , "could not open relation with OID %u" , relationId );
703
703
704
+ pgstat_initstats (r );
705
+
704
706
return r ;
705
707
}
706
708
@@ -743,6 +745,8 @@ try_relation_open(Oid relationId, LOCKMODE lockmode)
743
745
if (!RelationIsValid (r ))
744
746
elog (ERROR , "could not open relation with OID %u" , relationId );
745
747
748
+ pgstat_initstats (r );
749
+
746
750
return r ;
747
751
}
748
752
@@ -787,6 +791,8 @@ relation_open_nowait(Oid relationId, LOCKMODE lockmode)
787
791
if (!RelationIsValid (r ))
788
792
elog (ERROR , "could not open relation with OID %u" , relationId );
789
793
794
+ pgstat_initstats (r );
795
+
790
796
return r ;
791
797
}
792
798
@@ -873,8 +879,6 @@ heap_open(Oid relationId, LOCKMODE lockmode)
873
879
errmsg ("\"%s\" is a composite type" ,
874
880
RelationGetRelationName (r ))));
875
881
876
- pgstat_initstats (& r -> pgstat_info , r );
877
-
878
882
return r ;
879
883
}
880
884
@@ -903,8 +907,6 @@ heap_openrv(const RangeVar *relation, LOCKMODE lockmode)
903
907
errmsg ("\"%s\" is a composite type" ,
904
908
RelationGetRelationName (r ))));
905
909
906
- pgstat_initstats (& r -> pgstat_info , r );
907
-
908
910
return r ;
909
911
}
910
912
@@ -954,8 +956,6 @@ heap_beginscan(Relation relation, Snapshot snapshot,
954
956
else
955
957
scan -> rs_key = NULL ;
956
958
957
- pgstat_initstats (& scan -> rs_pgstat_info , relation );
958
-
959
959
initscan (scan , key );
960
960
961
961
return scan ;
@@ -1059,7 +1059,7 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
1059
1059
*/
1060
1060
HEAPDEBUG_3 ; /* heap_getnext returning tuple */
1061
1061
1062
- pgstat_count_heap_getnext (& scan -> rs_pgstat_info );
1062
+ pgstat_count_heap_getnext (scan -> rs_rd );
1063
1063
1064
1064
return & (scan -> rs_ctup );
1065
1065
}
@@ -1086,6 +1086,10 @@ heap_getnext(HeapScanDesc scan, ScanDirection direction)
1086
1086
* and return it in *userbuf (so the caller must eventually unpin it); when
1087
1087
* keep_buf = false, the pin is released and *userbuf is set to InvalidBuffer.
1088
1088
*
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
+ *
1089
1093
* It is somewhat inconsistent that we ereport() on invalid block number but
1090
1094
* return false on invalid item number. There are a couple of reasons though.
1091
1095
* One is that the caller can relatively easily check the block number for
@@ -1101,12 +1105,12 @@ heap_fetch(Relation relation,
1101
1105
HeapTuple tuple ,
1102
1106
Buffer * userbuf ,
1103
1107
bool keep_buf ,
1104
- PgStat_Info * pgstat_info )
1108
+ Relation stats_relation )
1105
1109
{
1106
1110
/* Assume *userbuf is undefined on entry */
1107
1111
* userbuf = InvalidBuffer ;
1108
1112
return heap_release_fetch (relation , snapshot , tuple ,
1109
- userbuf , keep_buf , pgstat_info );
1113
+ userbuf , keep_buf , stats_relation );
1110
1114
}
1111
1115
1112
1116
/*
@@ -1125,7 +1129,7 @@ heap_release_fetch(Relation relation,
1125
1129
HeapTuple tuple ,
1126
1130
Buffer * userbuf ,
1127
1131
bool keep_buf ,
1128
- PgStat_Info * pgstat_info )
1132
+ Relation stats_relation )
1129
1133
{
1130
1134
ItemPointer tid = & (tuple -> t_self );
1131
1135
ItemId lp ;
@@ -1210,9 +1214,9 @@ heap_release_fetch(Relation relation,
1210
1214
*/
1211
1215
* userbuf = buffer ;
1212
1216
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 );
1216
1220
1217
1221
return true;
1218
1222
}
@@ -1517,7 +1521,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
1517
1521
*/
1518
1522
CacheInvalidateHeapTuple (relation , heaptup );
1519
1523
1520
- pgstat_count_heap_insert (& relation -> pgstat_info );
1524
+ pgstat_count_heap_insert (relation );
1521
1525
1522
1526
/*
1523
1527
* 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,
1807
1811
if (have_tuple_lock )
1808
1812
UnlockTuple (relation , & (tp .t_self ), ExclusiveLock );
1809
1813
1810
- pgstat_count_heap_delete (& relation -> pgstat_info );
1814
+ pgstat_count_heap_delete (relation );
1811
1815
1812
1816
return HeapTupleMayBeUpdated ;
1813
1817
}
@@ -2269,7 +2273,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
2269
2273
if (have_tuple_lock )
2270
2274
UnlockTuple (relation , & (oldtup .t_self ), ExclusiveLock );
2271
2275
2272
- pgstat_count_heap_update (& relation -> pgstat_info );
2276
+ pgstat_count_heap_update (relation );
2273
2277
2274
2278
/*
2275
2279
* If heaptup is a private copy, release it. Don't forget to copy t_self
0 commit comments