Skip to content

Commit 2904324

Browse files
committed
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
1 parent af0c248 commit 2904324

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/backend/access/heap/heapam.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,9 @@ heapgettup_pagemode(HeapScanDesc scan,
10521052
linesleft = scan->rs_ntuples;
10531053
lineindex = ScanDirectionIsForward(dir) ? 0 : linesleft - 1;
10541054

1055+
/* block is the same for all tuples, set it once outside the loop */
1056+
ItemPointerSetBlockNumber(&tuple->t_self, scan->rs_cblock);
1057+
10551058
/* lineindex now references the next or previous visible tid */
10561059
continue_page:
10571060

@@ -1067,7 +1070,7 @@ heapgettup_pagemode(HeapScanDesc scan,
10671070

10681071
tuple->t_data = (HeapTupleHeader) PageGetItem(page, lpp);
10691072
tuple->t_len = ItemIdGetLength(lpp);
1070-
ItemPointerSet(&(tuple->t_self), scan->rs_cblock, lineoff);
1073+
ItemPointerSetOffsetNumber(&tuple->t_self, lineoff);
10711074

10721075
/* skip any tuples that don't match the scan key */
10731076
if (key != NULL &&

0 commit comments

Comments
 (0)