From f0b8920b23b200132a4e92942c4bb281426e4f9c Mon Sep 17 00:00:00 2001 From: David Rowley Date: Mon, 31 Oct 2022 10:05:12 +1300 Subject: [PATCH v2 5/5] Prefetch tuple memory during forward seqscans --- src/backend/access/heap/heapam.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 8fe4f4c837..6dc53effb4 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -1115,6 +1115,17 @@ heapgettup_pagemode(HeapScanDesc scan, tuple->t_len = ItemIdGetLength(lpp); ItemPointerSet(&(tuple->t_self), block, lineoff); + /* + * Prefetching the memory for the next tuple has shown to improve + * performance on certain hardware. + */ + if (!backward && linesleft > 1) + { + lineoff = scan->rs_vistuples[lineindex + 1]; + lpp = PageGetItemId(page, lineoff); + pg_prefetch_mem(PageGetItem(page, lpp)); + } + /* * if current tuple qualifies, return it. */ -- 2.35.1.windows.2