@@ -53,16 +53,6 @@ typedef struct
53
53
* 1. Otherwise every access would need to subtract 1.
54
54
*/
55
55
bool marked [MaxHeapTuplesPerPage + 1 ];
56
-
57
- /*
58
- * Tuple visibility is only computed once for each tuple, for correctness
59
- * and efficiency reasons; see comment in heap_page_prune() for details.
60
- * This is of type int8[], instead of HTSV_Result[], so we can use -1 to
61
- * indicate no visibility has been computed, e.g. for LP_DEAD items.
62
- *
63
- * Same indexing as ->marked.
64
- */
65
- int8 htsv [MaxHeapTuplesPerPage + 1 ];
66
56
} PruneState ;
67
57
68
58
/* Local functions */
@@ -71,6 +61,7 @@ static HTSV_Result heap_prune_satisfies_vacuum(PruneState *prstate,
71
61
Buffer buffer );
72
62
static int heap_prune_chain (Buffer buffer ,
73
63
OffsetNumber rootoffnum ,
64
+ int8 * htsv ,
74
65
PruneState * prstate );
75
66
static void heap_prune_record_prunable (PruneState * prstate , TransactionId xid );
76
67
static void heap_prune_record_redirect (PruneState * prstate ,
@@ -240,6 +231,10 @@ heap_page_prune(Relation relation, Buffer buffer,
240
231
prstate .nredirected = prstate .ndead = prstate .nunused = 0 ;
241
232
memset (prstate .marked , 0 , sizeof (prstate .marked ));
242
233
234
+ /*
235
+ * presult->htsv is not initialized here because all ntuple spots in the
236
+ * array will be set either to a valid HTSV_Result value or -1.
237
+ */
243
238
presult -> ndeleted = 0 ;
244
239
presult -> nnewlpdead = 0 ;
245
240
@@ -276,7 +271,7 @@ heap_page_prune(Relation relation, Buffer buffer,
276
271
/* Nothing to do if slot doesn't contain a tuple */
277
272
if (!ItemIdIsNormal (itemid ))
278
273
{
279
- prstate . htsv [offnum ] = -1 ;
274
+ presult -> htsv [offnum ] = -1 ;
280
275
continue ;
281
276
}
282
277
@@ -292,8 +287,8 @@ heap_page_prune(Relation relation, Buffer buffer,
292
287
if (off_loc )
293
288
* off_loc = offnum ;
294
289
295
- prstate . htsv [offnum ] = heap_prune_satisfies_vacuum (& prstate , & tup ,
296
- buffer );
290
+ presult -> htsv [offnum ] = heap_prune_satisfies_vacuum (& prstate , & tup ,
291
+ buffer );
297
292
}
298
293
299
294
/* Scan the page */
@@ -317,7 +312,8 @@ heap_page_prune(Relation relation, Buffer buffer,
317
312
continue ;
318
313
319
314
/* Process this item or chain of items */
320
- presult -> ndeleted += heap_prune_chain (buffer , offnum , & prstate );
315
+ presult -> ndeleted += heap_prune_chain (buffer , offnum ,
316
+ presult -> htsv , & prstate );
321
317
}
322
318
323
319
/* Clear the offset information once we have processed the given page. */
@@ -446,6 +442,8 @@ heap_prune_satisfies_vacuum(PruneState *prstate, HeapTuple tup, Buffer buffer)
446
442
/*
447
443
* Prune specified line pointer or a HOT chain originating at line pointer.
448
444
*
445
+ * Tuple visibility information is provided in htsv.
446
+ *
449
447
* If the item is an index-referenced tuple (i.e. not a heap-only tuple),
450
448
* the HOT chain is pruned by removing all DEAD tuples at the start of the HOT
451
449
* chain. We also prune any RECENTLY_DEAD tuples preceding a DEAD tuple.
@@ -473,7 +471,8 @@ heap_prune_satisfies_vacuum(PruneState *prstate, HeapTuple tup, Buffer buffer)
473
471
* Returns the number of tuples (to be) deleted from the page.
474
472
*/
475
473
static int
476
- heap_prune_chain (Buffer buffer , OffsetNumber rootoffnum , PruneState * prstate )
474
+ heap_prune_chain (Buffer buffer , OffsetNumber rootoffnum ,
475
+ int8 * htsv , PruneState * prstate )
477
476
{
478
477
int ndeleted = 0 ;
479
478
Page dp = (Page ) BufferGetPage (buffer );
@@ -494,7 +493,7 @@ heap_prune_chain(Buffer buffer, OffsetNumber rootoffnum, PruneState *prstate)
494
493
*/
495
494
if (ItemIdIsNormal (rootlp ))
496
495
{
497
- Assert (prstate -> htsv [rootoffnum ] != -1 );
496
+ Assert (htsv [rootoffnum ] != -1 );
498
497
htup = (HeapTupleHeader ) PageGetItem (dp , rootlp );
499
498
500
499
if (HeapTupleHeaderIsHeapOnly (htup ))
@@ -517,7 +516,7 @@ heap_prune_chain(Buffer buffer, OffsetNumber rootoffnum, PruneState *prstate)
517
516
* either here or while following a chain below. Whichever path
518
517
* gets there first will mark the tuple unused.
519
518
*/
520
- if (prstate -> htsv [rootoffnum ] == HEAPTUPLE_DEAD &&
519
+ if (htsv [rootoffnum ] == HEAPTUPLE_DEAD &&
521
520
!HeapTupleHeaderIsHotUpdated (htup ))
522
521
{
523
522
heap_prune_record_unused (prstate , rootoffnum );
@@ -585,7 +584,6 @@ heap_prune_chain(Buffer buffer, OffsetNumber rootoffnum, PruneState *prstate)
585
584
break ;
586
585
587
586
Assert (ItemIdIsNormal (lp ));
588
- Assert (prstate -> htsv [offnum ] != -1 );
589
587
htup = (HeapTupleHeader ) PageGetItem (dp , lp );
590
588
591
589
/*
@@ -605,7 +603,7 @@ heap_prune_chain(Buffer buffer, OffsetNumber rootoffnum, PruneState *prstate)
605
603
*/
606
604
tupdead = recent_dead = false;
607
605
608
- switch (( HTSV_Result ) prstate -> htsv [offnum ])
606
+ switch (htsv_get_valid_status ( htsv [offnum ]) )
609
607
{
610
608
case HEAPTUPLE_DEAD :
611
609
tupdead = true;
0 commit comments