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 <
[email protected]>
Discussion: https://www.postgresql.org/message-id/lxzj26ga6ippdeunz6kuncectr5gfuugmm2ry22qu6hcx6oid6@lzx3sjsqhmt6
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:
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 &&