Re: index prefetching

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: Tomas Vondra <tomas(at)vondra(dot)me>
Cc: Andres Freund <andres(at)anarazel(dot)de>, 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-09-04 01:07:44
Message-ID: CAH2-Wzky5vZ0GJ90WKy=mVmKLO=4o2A+9goXKdM9FCJiUYMaBA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 19, 2026 at 4:00 PM Peter Geoghegan <pg(at)bowt(dot)ie> wrote:
> Attached is v33, another revision intended only to fix bit rot.

Attached is v34. My focus was on fixing regressions in the first patch
(the "Add slot-based table AM index scan interface" one), which I'm
now very close to pushing. I pushed 3 small pieces from that same
patch earlier today.

These regressions were in index-only scans, which are more sensitive
to the extra indirection added by the slot interface. We can make up
for that to some extent with the amgetbatch interface, where most
calls to table_index_getnext_slot won't actually need to call
amgetbatch. Whereas with an amgettuple index AM, all calls to
table_index_getnext_slot are passed through to amggettuple. So I had
to micro-optimize some more to compensate; I didn't want to assume
that the amgetbatch work would eventually be committed and fix these
regressions.

And so v34 makes heapam_index_getnext_slot a little bit more
complicated to deal with those problems. With index-only scans,
actually performing a heap fetch is the slow path, so we don't inline
heapam_index_heap_fetch into heapam_index_getnext_slot anymore. It's
still important that plain scans inline heapam_index_heap_fetch into
their own specialized version of heapam_index_getnext_slot (for both
the ambatch and amgettuple specializations of
heapam_index_getnext_slot).

Other changes, all of which are also in the first patch:

* v34 also simplifies fetch_tid, the interface that we use during
constraint enforcement, in _bt_check_unique and one or two other
places. We no longer use a slot there at all, restoring the Postgres
11 behavior, or close to it (prior to the initial table AM work in
Postgres 12, we just called heap_hot_search_buffer directly, which is
close to what we're done now with fetch_tid).

* We now make index_getnext_tid (the shim function that calls through
to amgettuple) into an inline function in the first commit, not just
the later amgetbatch commit.

I moved index_getnext_tid into amapi.h, which required adding 3 new
headers to amapi.h. I think that this is probably acceptable, but I
wanted to flag it as a possible concern. This is the logical place to
put index_getnext_tid, if we have to inline it -- and it seems like
that's more or less required.

* I got rid of the index-only scan + btree/name_ops memory context,
which wasn't really necessary.

--
Peter Geoghegan

Attachment Content-Type Size
v34-0012-WIP-aio-bufmgr-Fix-race-condition-leading-to-dea.patch application/octet-stream 3.1 KB
v34-0009-Add-EXPLAIN-IO-support-for-plain-index-scans.patch application/octet-stream 13.9 KB
v34-0011-aio-Fix-pgaio_io_wait-for-staged-IOs-B.patch application/octet-stream 6.3 KB
v34-0001-Add-slot-based-table-AM-index-scan-interface.patch application/octet-stream 102.9 KB
v34-0010-Allow-read_stream_reset-to-not-wait-for-IO-compl.patch application/octet-stream 20.7 KB
v34-0008-heapam-Add-index-scan-I-O-prefetching.patch application/octet-stream 54.8 KB
v34-0007-heapam-Optimize-pin-transfers-during-index-scans.patch application/octet-stream 6.1 KB
v34-0006-WIP-Adopt-amgetbatch-interface-in-SP-GiST-index-.patch application/octet-stream 70.4 KB
v34-0005-WIP-Adopt-amgetbatch-interface-in-GiST-index-AM.patch application/octet-stream 113.4 KB
v34-0004-Adopt-amgetbatch-interface-in-hash-index-AM.patch application/octet-stream 48.1 KB
v34-0002-Limit-get_actual_variable_range-leaf-page-reads.patch application/octet-stream 7.8 KB
v34-0003-Add-amgetbatch-interface-and-adopt-it-in-nbtree.patch application/octet-stream 270.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayoub Kazar 2026-09-04 01:20:12 Re: Add pg_stat_vfdcache view for VFD cache statistics
Previous Message Tom Lane 2026-09-04 01:00:26 Re: CREATE SCHEMA ... CREATE DOMAIN support