Re: index prefetching
Andres Freund <andres@anarazel.de>
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
Hi, On 2025-08-28 19:08:40 +0200, Tomas Vondra wrote: > On 8/28/25 18:16, Andres Freund wrote: > >> So I think the IPC overhead with "worker" can be quite significant, > >> especially for cases with distance=1. I don't think it's a major issue > >> for PG18, because seq/bitmap scans are unlikely to collapse the distance > >> like this. And with larger distances the cost amortizes. It's much > >> bigger issue for the index prefetching, it seems. > > > > I couldn't keep up with all the discussion, but is there actually valid I/O > > bound cases (i.e. not ones were we erroneously keep the distance short) where > > index scans end can't have a higher distance? > > > > I don't know, really. > > Is the presented exaple really a case of an "erroneously short > distance"? I think the query isn't actually measuring something particularly useful in the general case. You're benchmarking something were the results are never looked at - which means the time between two index fetches is unrealistically short. That means any tiny latency increase matters a lot more than with realistic queries. And this is, IIUC, on a local SSD. I'd bet that on cloud latencies AIO would still be a huge win. > From the 2x regression (compared to master) it might seem like that, but > even with the increased distance it's still slower than master (by 25%). So > maybe the "error" is to use AIO in these cases, instead of just switching to > I/O done by the backend. If it's slower at a higher distance, we're missing something. > It may be a bit worse for non-btree indexes, e.g. for for ordered scans > on gist indexes (getting the next tuple may require reading many leaf > pages, so maybe we can't look too far ahead?). Or for indexes with > naturally "fat" tuples, which limits how many tuples we see ahead. I am not worried at all about those cases. If you have to read a lot of index leaf pages to get a heap fetch, a distance of even just 2 will be fine, because the IPC overhead is a neglegible cost compared to the index processing. Similarly, if you have to do very deep index traversals due to wide index tuples, there's going to be more time between two table fetches. > > Obviously you can construct cases with a low distance by having indexes point > > to a lot of tiny tuples pointing to perfectly correlated pages, but in that > > case IO can't be a significant factor. > > > > It's definitely true the examples the script finds are "adversary", but > also not entirely unrealistic. I think doing index scans where the results are just thrown out are entirely unrealistic... > I suppose there will be such cases for any heuristics we come up with. Agreed. > There's probably more cases like this, where we end up with many hits. > Say, a merge join may visit index tuples repeatedly, and so on. But then > it's likely in shared buffers, so there won't be any IPC. Yea, I'd not expect a meaningful impact of any of this in a workload like that. Greetings, Andres Freund