1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-20 00:42:27 +03:00

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
This commit is contained in:
Heikki Linnakangas 2025-04-01 13:24:27 +03:00
parent af0c248557
commit 2904324a88

View File

@ -1052,6 +1052,9 @@ heapgettup_pagemode(HeapScanDesc scan,
linesleft = scan->rs_ntuples; linesleft = scan->rs_ntuples;
lineindex = ScanDirectionIsForward(dir) ? 0 : linesleft - 1; 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 */ /* lineindex now references the next or previous visible tid */
continue_page: continue_page:
@ -1067,7 +1070,7 @@ continue_page:
tuple->t_data = (HeapTupleHeader) PageGetItem(page, lpp); tuple->t_data = (HeapTupleHeader) PageGetItem(page, lpp);
tuple->t_len = ItemIdGetLength(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 */ /* skip any tuples that don't match the scan key */
if (key != NULL && if (key != NULL &&