Repository navigation
Description
Is there an existing issue for performance?
- I have checked the existing issues.
Environment
- Version or commit-id: main 041d10af37
- Hardware parameters: Apple M2 Max, 12 cores, 32 GB; MinIO (local) as SHARED backend
- OS type: macOS
- Others: single CN; [fileservice.cache] memory-capacity = "1GB", disk-capacity = "4GB"Details of Performance
An IVFFLAT query that reads a column not stored in the index (a WHERE filter or a projected column, no INCLUDE columns) is 13–22× slower than the same query without it, because the join back to the source table thrashes the disk cache with whole-object prefetches.
Data: wiki_all 1M (768-dim vecf32) in w(id bigint pk, cat int, emb vecf32(768)), cat = id % 100. IVFFLAT lists=1000, probe_limit=8, 150–300 queries per batch.
| Query | avg | p50 | p95 |
|---|---|---|---|
select id from w order by l2_distance(emb, q) limit 10 |
37 ms | 20 ms | 70 ms |
select id, cat from w order by ... limit 10 |
474 ms | 442 ms | 1128 ms |
select id from w where cat < 10 order by ... limit 10 |
645–800 ms | 484–552 ms | 1.8–2.0 s |
Cause. The local data source prefetches every object it is about to touch as a whole object into the disk cache (pkg/vm/engine/disttae/local_disttae_datasource.go, ioutil.Prefetch → S3FS.PrefetchFile). It skips this when the read policy carries SkipFullFilePreloads, but the join back to the source table is an ordinary table scan (Table Scan on wiki.w, Runtime Filter Probe: w.id, estimated 5–10 rows over 2–4 blocks) that runs with the default policy, and no plan field carries a read policy to a scan. The join back to the source reads about 50 rows from about 38 blocks, but each touched object (about 145 MB) is downloaded in full. Entries objects plus source objects total 6.2 GB, which does not fit a 4 GB disk cache, so they evict each other on every query.
Fileservice cache trace over 750 filtered/projected queries:
- 91 distinct objects were downloaded 2,017 times: 118 GB of whole-object fetches for 2.96 GB of distinct data.
- About 325 MB was fetched from S3 per query, to read about 2 MB of the source table.
- Memory-cache hit rate on the source table stays at 99%, because the prefetch completes before the read. The cost shows up as S3 bandwidth, disk-cache churn and latency, not as memory misses.
- A CPU profile shows the process mostly idle;
S3FS.PrefetchFile→DiskCache.setFileis the largest CPU consumer.
Confirmation. Same data and queries:
| Disk cache | Filtered query avg | p95 |
|---|---|---|
| 4 GB (default behavior) | 494–638 ms | 1.5–1.7 s |
| 16 GB (all whole objects fit) | 18–28 ms | 39–108 ms |
| 4 GB, whole-object fills disabled, ranges cached instead (experimental switch) | 17.7 ms warm | 39 ms |
Whole-object fills are still needed for scans. With whole-object fills disabled, TPC-H SF10 (22 queries) got much slower: 295 s / 110 s per round versus 59 s / 52 s. The fix therefore cannot simply turn whole-object prefetch off. The fill unit has to follow the access pattern: narrow reads (point/primary-key lookups, the IVFFLAT join back to the source, filtered entries scans) should fill only the ranges they read, and scans should keep whole-object fills.
Resolution (scope: IVFFLAT):
- perf(fileservice): prefetch whole objects for narrow scans only while the disk cache keeps them #32034: the IVFFLAT join back and the entries search are marked as narrow reads in the plan; a narrow read skips whole-object prefetch only while the disk cache evicts whole objects before most of them are read.
- perf(fileservice): decide whole-object prefetch of narrow reads per table #32040: the decision is per table, so a table that fits (the entries table at 1 GB memory / 4 GB disk) keeps whole-object prefetch while another table (the base table) thrashes. The pre-filter join back is marked narrow too.
Out of scope: choosing the fill unit for other narrow reads (point and primary-key lookups) and changing the disk-tier eviction policy. Marking reads narrow by the share of an object's blocks they select was tried and made TPC-H SF10 slower (round one 64 s against 46 s, three times the S3 requests).
Additional information
- The comment on
RunWithSourceReadCacheSkip(pkg/sql/compile/plugin_context.go) and the IVFFLAT build comment (pkg/vectorindex/ivfflat/plugin/compile/compile.go) say that queries never re-read the source table. That is not true without INCLUDE columns: every query that filters or projects a non-INCLUDE column reads the source table. - These are local MinIO measurements. On real S3, per-request latency is much higher, which makes many small range reads costlier for scans. That is why the fill unit should be chosen per access pattern.
Activity
perf(fileservice): skip whole-object prefetch for narrow scans only w…
cpegeric commentedon Nov 2, 2026
Resolved for IVFFLAT by #32034 (merged) and #32040.
#32034
#32040
Filtered IVFFLAT query, 50 cold then 50 warm, avg ms (warm p95):
TPC-H SF10 is unchanged: no TPC-H table is marked narrow.
Out of scope: choosing the fill unit for other narrow reads (point and primary-key lookups) and the disk-tier eviction policy. Marking reads narrow by the share of an object's blocks they select was tried and made TPC-H slower (round one 64 s against 46 s, three times the S3 requests).
perf(fileservice): prefetch whole objects for narrow scans only while…
docs: link the per-table prefetch PR in the design note (matrixorigin…
perf(fileservice): decide narrow reads in S3FS.Read and forget evicte…
perf(fileservice): bound the per-table preload records (matrixorigin#…
perf(fileservice): decide whole-object prefetch of narrow reads per t…