5454#include "utils/spccache.h"
5555#include "utils/syscache.h"
5656
57+ void (* add_index_delete_hook ) (Relation indexRelation , ItemPointer heap_tid , TransactionId xmin ) = NULL ;
5758
5859static HeapTuple heap_prepare_insert (Relation relation , HeapTuple tup ,
5960 TransactionId xid , CommandId cid , int options );
@@ -364,6 +365,9 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
364365 * results for a non-MVCC snapshot, the caller must hold some higher-level
365366 * lock that ensures the interesting tuple(s) won't change.)
366367 */
368+ if (keep_startblock )
369+ goto skip_get_number_of_blocks ;
370+
367371 if (scan -> rs_base .rs_parallel != NULL )
368372 {
369373 bpscan = (ParallelBlockTableScanDesc ) scan -> rs_base .rs_parallel ;
@@ -372,6 +376,8 @@ initscan(HeapScanDesc scan, ScanKey key, bool keep_startblock)
372376 else
373377 scan -> rs_nblocks = RelationGetNumberOfBlocks (scan -> rs_base .rs_rd );
374378
379+ skip_get_number_of_blocks :
380+
375381 /*
376382 * If the table is large relative to NBuffers, use a bulk-read access
377383 * strategy and enable synchronized scanning (see syncscan.c). Although
@@ -2806,6 +2812,7 @@ heap_delete(Relation relation, ItemPointer tid,
28062812 bool all_visible_cleared = false;
28072813 HeapTuple old_key_tuple = NULL ; /* replica identity of the tuple */
28082814 bool old_key_copied = false;
2815+ TransactionId old_xmin ;
28092816
28102817 Assert (ItemPointerIsValid (tid ));
28112818
@@ -3052,6 +3059,8 @@ heap_delete(Relation relation, ItemPointer tid,
30523059 xid , LockTupleExclusive , true,
30533060 & new_xmax , & new_infomask , & new_infomask2 );
30543061
3062+ old_xmin = HeapTupleHeaderGetXmin (tp .t_data );
3063+
30553064 START_CRIT_SECTION ();
30563065
30573066 /*
@@ -3197,6 +3206,9 @@ heap_delete(Relation relation, ItemPointer tid,
31973206 if (old_key_tuple != NULL && old_key_copied )
31983207 heap_freetuple (old_key_tuple );
31993208
3209+ if (add_index_delete_hook )
3210+ add_index_delete_hook (relation , tid , old_xmin );
3211+
32003212 return TM_Ok ;
32013213}
32023214
@@ -3299,6 +3311,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
32993311 infomask2_old_tuple ,
33003312 infomask_new_tuple ,
33013313 infomask2_new_tuple ;
3314+ TransactionId old_xmin ;
33023315
33033316 Assert (ItemPointerIsValid (otid ));
33043317
@@ -3745,6 +3758,8 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
37453758 & xmax_old_tuple , & infomask_old_tuple ,
37463759 & infomask2_old_tuple );
37473760
3761+ old_xmin = HeapTupleHeaderGetRawXmin (oldtup .t_data );
3762+
37483763 /*
37493764 * And also prepare an Xmax value for the new copy of the tuple. If there
37503765 * was no xmax previously, or there was one but all lockers are now gone,
@@ -4228,6 +4243,9 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
42284243 bms_free (modified_attrs );
42294244 bms_free (interesting_attrs );
42304245
4246+ if (add_index_delete_hook )
4247+ add_index_delete_hook (relation , otid , old_xmin );
4248+
42314249 return TM_Ok ;
42324250}
42334251
0 commit comments