Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2025-04-01 10:24:27 +0000
committerHeikki Linnakangas2025-04-01 10:24:27 +0000
commit2904324a88f672b2ecc22735279c16d6e1ee178c (patch)
treec7cb55422baa961d887157f77bd96beccf63c27d /src/backend/access
parentaf0c248557aecb335462d980cb7319bdf85a5c66 (diff)
heapam: Only set tuple's block once per page in pagemode
Due to splitting the block id into two 16 bit integers, BlockIdSet() is more expensive than one might think. Doing it once per returned tuple shows up as a small but reliably reproducible cost. It's simple enough to set the block number just once per block in pagemode, so do so. Author: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/lxzj26ga6ippdeunz6kuncectr5gfuugmm2ry22qu6hcx6oid6@lzx3sjsqhmt6
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/heap/heapam.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 6e433db039e..cedaa195cb6 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1052,6 +1052,9 @@ heapgettup_pagemode(HeapScanDesc scan,
linesleft = scan->rs_ntuples;
lineindex = ScanDirectionIsForward(dir) ? 0 : linesleft - 1;
+ /* block is the same for all tuples, set it once outside the loop */
+ ItemPointerSetBlockNumber(&tuple->t_self, scan->rs_cblock);
+
/* lineindex now references the next or previous visible tid */
continue_page:
@@ -1067,7 +1070,7 @@ continue_page:
tuple->t_data = (HeapTupleHeader) PageGetItem(page, lpp);
tuple->t_len = ItemIdGetLength(lpp);
- ItemPointerSet(&(tuple->t_self), scan->rs_cblock, lineoff);
+ ItemPointerSetOffsetNumber(&tuple->t_self, lineoff);
/* skip any tuples that don't match the scan key */
if (key != NULL &&