Repository navigation
perf(fileservice): prefetch whole objects for narrow scans only while the disk cache keeps them - #32034
Conversation
…ect preloads (matrixorigin#32033) An IVFFLAT query that filters or projects a column outside the index joins the candidates back to the base table. That scan ran with the default policy, so the local data source prefetched every touched object whole into the disk cache to read a few rows; with entries and base objects larger than the disk cache, they evicted each other on every query. Plan nodes gain skip_full_file_preloads. The IVFFLAT rewrite sets it on the base table scan of the join back, the scope passes it to the table scan operator, and the operator adds SkipFullFilePreloads to its read context, which the data sources already honor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 0e36a09fb66f20f85f3888bc46c881b27039ed8a
Assessment: approve
The bounded IVFFLAT cache-policy fix is correctly scoped and propagated through local, parallel and remote scans. Caller policy bits and unaffected scan paths are preserved. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2
Validation:
-
Reviewed all 13 changed files, storage consumers, adaptive fallback isolation, operator lifecycle and regression-test oracles.
-
Static descriptor audit passed: field 97 is the sole descriptor change; frozen source is clean and git diff --check passed. Receipt: checks/1793636061561863019-2.json; output: descriptor-audit.log.
-
Frozen-head CI reports successful build, UT, static checks and both active BVT groups. Reviewed author-reported regression tests and controlled performance comparisons.
-
Saved review-plan.md, complete discussion-assessment.json and validation-evidence.json.
Limitations:
-
No fresh Go tests or benchmarks were run; supplied CI lacks individual test logs, and author-reported measurements were not independently reproduced.
-
Performance evidence covers single-CN MinIO; real S3 latency and multi-CN performance remain unmeasured.
…hile the disk cache thrashes (matrixorigin#32033) Replaces the fixed rule of the previous commit. Never prefetching whole objects for the IVFFLAT join back fixed the thrash with a small disk cache, but made the first pass about three times slower whenever the objects fit the cache. Each disk cache now measures the share of every whole-object file read before the file is evicted. When that share stays low it reports thrashing, and reads marked NarrowRead skip whole-object prefetch and cache the ranges they read; it stops after a quiet period with no evictions. The plan marks the IVFFLAT join back as a narrow scan (renamed from skip_full_file_preloads), and the IVFFLAT entries search reads as narrow. Other scans are unchanged. Design: docs/design/20261102-thrash-aware-prefetch.md Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
✅ Merged into
|
…stream claimed 97 as narrow_scan in matrixorigin#32034); take upstream narrow-scan prefetch, virtual-timestamp reads, temporal integer casts, vector shuffle ownership, JSON concat and logtail append-range changes GitHub reported the PR CONFLICTING (DIRTY): upstream matrixorigin#32034 added `plan.Node.narrow_scan = 97` while this branch's unmerged additive `ScanReadRole scan_read_role` sat on field 97. Semantic resolution, both sides kept: - upstream keeps `narrow_scan = 97` (shipped on main; `plan.pb.go` regenerated from the merged proto with the repository protoc/gogofast pipeline plus both postprocessors; toolchain verified byte-identical against upstream's committed bindings before use); - this branch's additive `scan_read_role` moves 97 -> 98; nothing ever persisted 97 as scan_read_role (unmerged field), provenance comment updated in proto/plan.proto; - `merged_descriptor_test.go` (upstream's merge-collision contract guard) extended to pin Node.narrow_scan=97 / Node.scan_read_role=98 so a future regeneration cannot silently renumber or drop either; - all other overlapping files auto-merged with both sides' hunks intact (upstream: table_scan/narrow-scan scope+operator plumbing, plan binder temporal/int-arg changes, disttae datasource, query_builder/types/ deepcopy/base_binder/apply_indices). Upstream batch: matrixorigin#31268 (virtual timestamp reads), matrixorigin#32001 (temporal integer casts), matrixorigin#32020 (vector shuffle ownership), matrixorigin#32031 (logtail append ranges), matrixorigin#32038 (python JSON-string concatenation; upstream's own change, no PR-side code), matrixorigin#32034 (narrow-scan prefetch).
…able (#32040) ## What type of PR is this? - [ ] API-change - [ ] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue #32033 ## What this PR does / why we need it: Follow-up to #32034. #32034 keeps one thrash signal per disk cache: when one table thrashes, every narrow read switches to range reads, including tables that would fit. This PR keeps one signal per table. **Design** (`docs/design/20261102-thrash-aware-prefetch.md`, updated): - Each narrow read tells the disk cache which table it reads for; the cache maps the objects narrow reads touch to their table and tracks the read share of each table's evicted whole-object files. - A table switches to range reads when that share averages below 0.1 over 4 evictions, or below 0.4 over 16. Of two tables evicting each other, the one using its whole objects least switches first, and the other usually fits after that. - A table switches back after 30 s with no eviction of its own whole-object files. The period doubles, up to 10 min, when it thrashes again soon after. - The IVFFLAT pre-filter join back (`JOIN(base, SEMI(search, filter scan))`) is now marked narrow like the plain join back; the filter scan copied from the base scan is not. - The decision is made in `S3FS.Read` for every narrow read, from the table in the read context; reads of no table are never skipped. - Scans read with their table id: taken from the table definition, or from the plan node's object reference when the rewritten table definition has none. **Measurements** (wiki_all 1M, IVFFLAT lists=1000, probe_limit=8, filtered query, MinIO, empty disk cache; 50 cold, 50 warm, 35 s pause, 50 more; avg ms, p95 in brackets): | Memory / disk | #32034: cold / warm / after pause | this PR: cold / warm / after pause | |---|---|---| | 1 / 4 GB (4 runs) | 162 (401) / 46 (223) / 68 | 122–194 (364–604) / 22–31 (60–127) / 45–64 | | 0.5 / 1.5 GB (3 runs) | 515 / 149 / 136 | 485 / 138 / 197 | | 1 / 8 GB | 102 / 16 | 82 / 16 | - At 1 / 4 GB only the base table switches; the entries search keeps whole objects. - At 0.5 / 1.5 GB both tables switch; cold is better and warm is the same. After the pause two of three runs were worse (210 and 233 vs 129 ms) and one the same (147 vs 142). - TPC-H SF10 at 1 / 4 GB, two rounds: 44.7 s / 53.4 s, 3,255 S3 requests, against 46.3 s / 51.2 s, 3,362 for #32034. No TPC-H table switches. **Not in this PR:** marking reads narrow by the share of an object's blocks they select (point and primary-key lookups without a plan mark). Tried and rejected: the TPC-H joins with selective runtime filters became narrow, and TPC-H round one took 64 s with 9,678 S3 requests. **Tests:** per-table signal unit tests (separation, tiered trip, own quiet period, doubling, deletes, bounds), a real disk cache reporting a group, S3FS per-group decision, the prefetch gate and both data sources, table id reaching the read context from the scan operator, the scope fallback to the object reference, the IVFFLAT entries search, and the pre-filter join back plan mark. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Approved-by: XuPeng-SH <[email protected]> Approved-by: gouhongshen <[email protected]> Approved-by: fengttt <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #32033
What this PR does / why we need it:
A table scan prefetches every object it is about to read into the CN disk cache as a whole object. That suits scans that read most of each object. For scans that read a few rows from each object, it fails whenever the touched objects do not fit the disk cache:
In that case every query downloads whole objects that are evicted before they are used again. On wiki_all 1M with a 4 GB disk cache, 91 objects were downloaded 2,017 times for 750 queries, and a filtered query took 500–800 ms instead of 17 ms. At 88M vectors the cache can never hold these objects.
Never prefetching for these scans is not the answer either: when the objects fit, it makes the first pass about three times slower (cold p95 760 ms against 150 ms). This PR prefetches only while the disk cache keeps what it fetches.
Design:
docs/design/20261102-thrash-aware-prefetch.mdNarrowRead. While the cache reports thrashing, a narrow read skips whole-object prefetch and caches the ranges it reads on disk. Otherwise it behaves exactly as before.plan.Node.narrow_scan(field 97) marks the base-table scan of the IVFFLAT join back. The scope passes it to thetable_scanoperator asNarrowRead.NarrowRead.SkipFullFilePreloads, as before.Measurements
wiki_all 1M (768-dim vecf32), IVFFLAT lists=1000, probe_limit=8. Filtered query:
select id from w where cat < 10 order by l2_distance(emb, q) limit 10. Single CN on MinIO; the disk cache is empty at the start of each run. Milliseconds, average (p95).Alternatives measured and rejected are listed in the design note:
Tests
pkg/fileservice/disk_cache_preload_test.gocovers the signal:FullFilePreloadsSkipped.It also includes a real disk cache that reports thrashing, and an S3FS narrow read that switches to range caching while thrashing.
Planner, scope and operator tests check that the join back is marked narrow, the index-only path is not, the mark survives a deep copy, and the reader receives
NarrowRead.Each targeted test fails with its production change removed.
go vetpasses, as do the full suites ofpkg/fileservice,pkg/sql/colexec/table_scan,pkg/sql/compile,pkg/sql/plan,pkg/vectorindex/ivfflat,pkg/vm/engine/readutilandpkg/pb/plan, and thepkg/vm/engine/disttaedatasource tests.🤖 Generated with Claude Code