| From: | Tomas Vondra <tomas(at)vondra(dot)me> |
|---|---|
| To: | Peter Geoghegan <pg(at)bowt(dot)ie>, Rui Zhao <zhaorui126(at)gmail(dot)com> |
| 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-10-12 19:38:55 |
| Message-ID: | fcf9030d-150c-4ce8-89f5-83c8e5f4355f@vondra.me |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
I went through this patch series again, mostly to learn about the
various recent improvements, look for stale comments/docs, etc. And to
see if something seems "surprising".
I only found a couple minor points;
1) I got a bit confused by tableam_index_pos_advance and how it
interacts with tableam_index_pos_advance, and how it affects the "valid"
flag of the position. I mean that:
- if tableam_index_pos_advance succeeds, the position keeps valid=true
(which seems logical) and points at a valid item in the batch
- if tableam_index_pos_advance fails, the position still has valid=true
(which may seem a bit surprising), and we do different things. If the
ringbuffer is full (or we're throttling), we undo the position advance
(thus making it point at a valid item again). But for BATCH_POS_DONE
we don't do that, we leave it pointing kinda "out of bounds".
The BatchRingItemPos definition says:
/* Position references a valid IndexScanDescData.batchbuf[] entry? */
bool valid;
and this seems to contradict the spirit of that, no? Because we're
leaving the position with valid=true, yet it's pointing outside the
current batch.
I'm not claiming this is broken, I just keep getting confused/distracted
by this. I recall we discussed it in the past (a couple months back?).
Maybe it'd be worth a comment somewhere?
2) The explanation (both in docs and comments) when we start prefetching
was talking about number of distinct blocks, but that's quite not what
xs_blkswitch_count counts. [prefetch-start-docs.patch]
3) It's probably worth mentioning that nearest-neighbor searches disable
index-only scans in the relevant sgml docs. [gist-ios-ordering.patch]
4) I struggle to understand why read_stream_grow_repeats needs +1
elements in stream->repeats. It seems pretty confusing, and also
"infecting" various other places with the +1. Smells like off-by-one
bugs in the future.
5) I noticed show_scan_io_usage may not be sufficiently careful about
checking iss_Instrument. I've been unable to make it fail with the
in-core scans, but I suspect it might dereference NULL with custom
scans or whatever. It probably should do the checks similarly to
show_indexscan_info. That's my patch, so it's up to me to get that
fixed (that patch probably needs more improvements).
I've been running a bunch of stress tests and benchmarks, looking for
crashes and regressions, but that found nothing significant so far.
regards
--
Tomas Vondra
| Attachment | Content-Type | Size |
|---|---|---|
| gist-ios-ordering.patch | text/x-patch | 1.0 KB |
| prefetch-start-docs.patch | text/x-patch | 1.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Lakhin | 2026-10-12 20:00:01 | Test publication.sql racing with subscription.sql might fail due to cache lookup error |
| Previous Message | Greg Burd | 2026-10-12 19:24:08 | Re: UNDO with constant time recovery (CTR) |