Re: index prefetching
Tomas Vondra <tomas.vondra@enterprisedb.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
aio: io_uring: Trigger async processing for large IOs
- a9ee66881744 19 (unreleased) landed
-
read stream: Split decision about look ahead for AIO and combining
- 8ca147d582a5 19 (unreleased) landed
-
read_stream: Only increase read-ahead distance when waiting for IO
- f63ca3379025 19 (unreleased) landed
-
read_stream: Prevent distance from decaying too quickly
- 6e36930f9aaf 19 (unreleased) landed
-
Reduce ExecSeqScan* code size using pg_assume()
- b227b0bb4e03 19 (unreleased) cited
-
Fix rare bug in read_stream.c's split IO handling.
- b421223172a2 19 (unreleased) cited
-
Fix multiranges to behave more like dependent types.
- 3e8235ba4f9c 17.0 cited
-
Add EXPLAIN (MEMORY) to report planner memory consumption
- 5de890e3610d 17.0 cited
-
Optimize nbtree backward scan boundary cases.
- c9c0589fda0e 17.0 cited
-
Increment xactCompletionCount during subtransaction abort.
- 90c885cdab8b 14.0 cited
-
Add nbtree Valgrind buffer lock checks.
- 4a70f829d86c 14.0 cited
-
Add nbtree high key "continuescan" optimization.
- 29b64d1de7c7 12.0 cited
-
Reduce pinning and buffer content locking for btree scans.
- 2ed5b87f96d4 9.5.0 cited
-
Teach btree to handle ScalarArrayOpExpr quals natively.
- 9e8da0f75731 9.2.0 cited
Attachments
- v20231209-0001-prefetch-2023-11-24.patch (text/x-patch) patch v20231209-0001
- v20231209-0002-reworks.patch (text/x-patch) patch v20231209-0002
Hi, Here's a simplified version of the patch series, with two important changes from the last version shared on 2023/11/24. Firstly, it abandons the idea to use preadv2() to check page cache. This initially seemed like a great way to check if prefetching is needed, but in practice it seems so expensive it's not really beneficial (especially in the "cached" case, which is where it matters most). Note: There's one more reason to not want rely on preadv2() that I forgot to mention - it's a Linux-specific thing. I wouldn't mind using it to improve already acceptable behavior, but it doesn't seem like a great idea if performance without would be poor. Secondly, this reworks multiple aspects of the "layering". Until now, the prefetching info was stored in IndexScanDesc and initialized in indexam.c in the various "beginscan" functions. That was obviously wrong - IndexScanDesc is just a description of what the scan should do, not a place where execution state (which the prefetch queue is) should be stored. IndexScanState (and IndexOnlyScanState) is a more appropriate place, so I moved it there. This also means the various "beginscan" functions don't need any changes (i.e. not even get prefetch_max), which is nice. Because the prefetch state is created/initialized elsewhere. But there's a layering problem that I don't know how to solve - I don't see how we could make indexam.c entirely oblivious to the prefetching, and move it entirely to the executor. Because how else would you know what to prefetch? With index_getnext_tid() I can imagine fetching XIDs ahead, stashing them into a queue, and prefetching based on that. That's kinda what the patch does, except that it does it from inside index_getnext_tid(). But that does not work for index_getnext_slot(), because that already reads the heap tuples. We could say prefetching only works for index_getnext_tid(), but that seems a bit weird because that's what regular index scans do. (There's a patch to evaluate filters on index, which switches index scans to index_getnext_tid(), so that'd make prefetching work too, but I'd ignore that here. There are other index_getnext_slot() callers, and I don't think we should accept does not work for those places seems wrong (e.g. execIndexing/execReplication would benefit from prefetching, I think). The patch just adds a "prefetcher" argument to index_getnext_*(), and the prefetching still happens there. I guess we could move most of the prefether typedefs/code somewhere, but I don't quite see how it could be done in executor entirely. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company