Re: index prefetching

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Tomas Vondra <tomas(at)vondra(dot)me>, Alexandre Felipe <o(dot)alexandre(dot)felipe(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Georgios <gkokolatos(at)protonmail(dot)com>, Konstantin Knizhnik <knizhnik(at)garret(dot)ru>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Subject: Re: index prefetching
Date: 2026-03-19 17:44:16
Message-ID: CAH2-Wz=HJc+QV2AZ9mUY43aKL+n+a1JQ-7OGE=MOkqSAtoKJug@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 17, 2026 at 1:37 PM Peter Geoghegan <pg(at)bowt(dot)ie> wrote:
> v14 has already bitrot, so I'm posting this new v15 to keep the
> patchset applying cleanly.

And now v15 has bitrot. So here's a new v16. There are 2 notable updates here.

Most notably, I decided to take a more conservative approach to fixing
the issues with the selfuncs.c mechanism that gives up when
get_actual_variable_range does too much work during planning. Rather
than inventing a new approach that bases the decision to give up on
the number of leaf pages accessed, which has certain advantages [1], I
have decided to cut scope and more or less reimplement the existing
VISITED_PAGES_LIMIT mechanism on the heapam side. This was a pragmatic
choice; there is no clear consensus on whether the design I proposed
for this will be acceptable, and we lack the time to resolve those
issues now.

To recap, selfuncs.c can no longer be the place where
VISITED_PAGES_LIMIT is implemented, because the new slot-based
interface won't return until it finds a visible tuple. The new
higher-level interface simply cannot support callers that want to
count the number of heap pages examined themselves.

The other notable change aims to improve performance for cached
workloads through more aggressive specialization of callback routines
like heapam_index_getnext_slot. There are now a total of 4 versions:

1. One for index-only scans + amgetbatch.
2. One for one for index-only scans + amgettuple.
3. One for plain index scans + amgetbatch.
4. One for plain index scans + amgettuple.

I've also aggressively used pg_attribute_always_inline (without this
specialization, performance ends up worse rather than better).

There might be some concerns about the distributed costs of increased
code size. But this revision is the fastest so far across all
available metrics (though of course the specialization work is
focussed on cached query performance specifically).

[1] (see https://www.postgresql.org/message-id/flat/CAH2-Wzkt1WkKp4VRJu3qHfmKXc8W%2BXYv1RXg5d2d3fSvAeO%3Drg%40mail.gmail.com)
--
Peter Geoghegan

Attachment Content-Type Size
v16-0015-WIP-aio-io_uring-Use-IO-size-not-IO-queue-to-tri.patch application/octet-stream 4.1 KB
v16-0014-WIP-read_stream-Prevent-distance-from-decaying-t.patch application/octet-stream 2.9 KB
v16-0017-Make-hash-index-AM-use-amgetbatch-interface.patch application/octet-stream 45.5 KB
v16-0016-Add-fake-LSN-support-to-hash-index-AM.patch application/octet-stream 14.0 KB
v16-0001-Make-IndexScanInstrumentation-a-pointer-in-execu.patch application/octet-stream 9.1 KB
v16-0013-WIP-read_stream-Only-increase-distance-when-wait.patch application/octet-stream 2.3 KB
v16-0011-WIP-aio-io_uring-Allow-IO-methods-to-check-if-IO.patch application/octet-stream 4.6 KB
v16-0012-bufmgr-Return-whether-WaitReadBuffers-needed-to-.patch application/octet-stream 2.8 KB
v16-0009-Don-t-wait-for-already-in-progress-IO.patch application/octet-stream 20.6 KB
v16-0010-WIP-read_stream-Issue-IO-synchronously-while-in-.patch application/octet-stream 2.0 KB
v16-0008-Make-buffer-hit-helper.patch application/octet-stream 6.0 KB
v16-0006-Use-ExecSetTupleBound-hint-during-index-scans.patch application/octet-stream 10.9 KB
v16-0005-Add-heapam-index-scan-I-O-prefetching.patch application/octet-stream 39.9 KB
v16-0004-Add-VISITED_PAGES_LIMIT-to-heapam.patch application/octet-stream 4.4 KB
v16-0007-Add-UnlockBufferGetLSN-utility-function.patch application/octet-stream 3.4 KB
v16-0003-Add-interfaces-that-enable-index-prefetching.patch application/octet-stream 262.6 KB
v16-0002-heapam-Track-heap-block-in-IndexFetchHeapData-us.patch application/octet-stream 3.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2026-03-19 17:56:55 Re: pgsql: Don't leave behind files in src dir in 007_multixact_conversion.
Previous Message Greg Burd 2026-03-19 17:36:29 Re: another autovacuum scheduling thread