From 9b670342c977ad41c26aec559c7e3390aab38867 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Thu, 28 May 2020 14:50:50 -0700 Subject: [PATCH] heapam: Don't re-inquire block number for each tuple during pruning. Author: Reviewed-By: Discussion: https://postgr.es/m/ Backpatch: --- src/backend/access/heap/pruneheap.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index 1794cfd8d9..08953f6f0a 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -44,6 +44,7 @@ typedef struct /* Local functions */ static int heap_prune_chain(Relation relation, Buffer buffer, + BlockNumber blockno, OffsetNumber rootoffnum, TransactionId OldestXmin, PruneState *prstate); @@ -185,6 +186,7 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, OffsetNumber offnum, maxoff; PruneState prstate; + BlockNumber blockno = BufferGetBlockNumber(buffer); /* * Our strategy is to scan the page and make lists of items to change, @@ -220,7 +222,8 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, continue; /* Process this item or chain of items */ - ndeleted += heap_prune_chain(relation, buffer, offnum, + ndeleted += heap_prune_chain(relation, buffer, + blockno, offnum, OldestXmin, &prstate); } @@ -349,7 +352,9 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin, * Returns the number of tuples (to be) deleted from the page. */ static int -heap_prune_chain(Relation relation, Buffer buffer, OffsetNumber rootoffnum, +heap_prune_chain(Relation relation, Buffer buffer, + BlockNumber blockno, + OffsetNumber rootoffnum, TransactionId OldestXmin, PruneState *prstate) { @@ -379,7 +384,7 @@ heap_prune_chain(Relation relation, Buffer buffer, OffsetNumber rootoffnum, tup.t_data = htup; tup.t_len = ItemIdGetLength(rootlp); - ItemPointerSet(&(tup.t_self), BufferGetBlockNumber(buffer), rootoffnum); + ItemPointerSet(&(tup.t_self), blockno, rootoffnum); if (HeapTupleHeaderIsHeapOnly(htup)) { -- 2.39.5