Repository navigation
Quantized Vector Search Rescoring Optimization - #123300
shankar-iyer wants to merge 17 commits into
Conversation
Replace the hand-written block header and checksum parsing in `MergeTreeReaderWide::readPointRows` with two small helpers: `decompressOnDiskCompressedBlock`, which decompresses one complete on-disk block through `CompressedReadBufferBase` (checksum verification included), and `readBytesAtOffset`, which reads a byte range with `readBigAt` when supported, otherwise with `seek` and `readStrict`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The writer stores every vector of a `Quantized` column as its own compressed block, so `MergeTreeReaderWide` reads only the rows requested by lazy materialization: one `readBigAt` per row, decompressed into the column with `CompressedReadBuffer`, which also verifies the checksum. Unrequested rows are returned as empty arrays and filtered out by the reader chain. Parts written before this layout are read the usual way. Removes the environment variable switch, the manual header and checksum parsing, and the helpers `decompressOnDiskCompressedBlock` and `readBytesAtOffset`, which are no longer needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The block-size arithmetic moves to `CompressionInfo.h`, the per-row payload size to the codec, and the elements substream and serialization are asked of `SerializationQuantizedVector` instead of reached for through `SerializationArray`. `useForPositionalReadAt` names the read settings `readBigAt` needs, and the point-read columns no longer deserialize prefixes they never use. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [52abfc4] Summary: ✅
AI ReviewSummaryAdds opt-in point reads for lazily materialized Findings❌ Blockers
Tests
Final Verdict❌ Block. Establish the actual per-part layout before positional reads and add the partition-transfer regression. The two author-dismissed performance concerns remain recorded above without further thread replies. Resolved the fixed adaptive-buffer thread; no new inline findings required a review batch. |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes18 object files changed (+54.71 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1932 translation units recompiled, 11885 s compile time in total, 1931 of them have a recent master baseline. Translation units without a recent master baseline:
|
| if (lazy_materializing_rows) | ||
| { | ||
| part_rows = &lazy_materializing_rows->rows_in_parts[getInfo().part_index_in_query]; | ||
| readers.main->prepareLazyMaterialization(part_rows); |
There was a problem hiding this comment.
prepareLazyMaterialization runs too late to protect the prefetched path.
MergeTreePrefetchedReadPool::PrefetchedReaders constructs the reader and calls prefetchBeginOfRange() before initializeIndexReader() reaches this line. At that point fixed_size_lazy_reads is still empty, so prefetchForAllColumns() still schedules the full ArrayElements ranges for the Quantized vector stream. On any path with read prefetch enabled, the query pays the whole-granule I/O up front and loses the main benefit this PR is trying to add.
Please initialize the lazy row state before the first prefetch, or make prefetchBeginOfRange() skip eligible Quantized element streams from part_rows without depending on fixed_size_lazy_reads.
There was a problem hiding this comment.
But lazy materialization will not use the prefetched pool ??
There was a problem hiding this comment.
Not on the in-order vector-search lazy branch itself: LazilyReadFromMergeTree builds LazyReadFromMergeTreeSource, and that source uses MergeTreeReadPoolInOrder rather than MergeTreePrefetchedReadPool.
The remaining problem is the generic unordered lazy branch used by optimizeLazyFinal: src/Processors/Sources/LazyUnorderedReadFromMergeTreeSource.cpp:128 wraps a plain ReadFromMergeTree, and src/Processors/QueryPlan/ReadFromMergeTree.cpp:759 can still choose MergeTreePrefetchedReadPool there. On that path prefetchBeginOfRange() fires before src/Storages/MergeTree/MergeTreeReadTask.cpp:424 reaches prepareLazyMaterialization, so the full ArrayElements ranges are already queued for prefetch.
There was a problem hiding this comment.
That looks a uncommon usage - SELECT ... FINAL with a quantized vector column and without a ORDER BY <dist>. I can disable the point read for lazy FINAL in follow up work.
|
Reworked from : #111180 |
|
@rschu1ze I ran this PR on the Weekly Stress Test and turned ON the optimization for Before (Storage) After (Storage) Before (Latency) After (Latency) - Note that increasing the multiplier is almost free now |
|
It looks like the PR will unboundedly increase random reads (GETs on object storage). for e.g if |
This reverts commit ba2442b. The rule priced a seek at `remote_read_min_bytes_for_seek` (4 MiB) per wanted row, so it switched to a whole-granule read at only 6 rows per granule. On a filesystem-cached disk that is never right: the cache keys on 4 MiB-aligned segments, candidates lie inside the granule, so a point read can never touch more segments than the granule itself spans. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Master moved the per-column read loop out of `readRows` into `readSegmentFromDisk` and added a columns cache around it, so the point-read hook moves with the loop. A point-read column holds only the requested rows, with empty arrays in between, so `prepareLazyMaterialization` turns the columns cache off for a reader that has any point read: such a column must neither become a cache entry nor be served from one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
|
||
| auto read_settings = settings.read_settings.adjustBufferSize(block_bytes); | ||
| read_settings.useForPositionalReadAt(); | ||
| auto buf = data_part_info_for_read->getDataPartStorage()->readFile(bin_path, read_settings, block_bytes); |
There was a problem hiding this comment.
This unconditionally enables the point-read path for any buffer that reports supportsReadAt(), but on uncached remote parts that still means one ranged request per shortlisted row. The direct S3/HTTP implementations issue a request inside each readBigAt call (src/IO/ReadBufferFromS3.cpp:299, src/IO/ReadWriteBufferFromHTTP.cpp:761), so a LIMIT 100 query with vector_search_index_fetch_multiplier = 20 can replace ~66 granule reads with ~2000 object-storage GETs even when the candidates cluster in a few granules.
That turns the advertised rescoring optimization into a latency/cost regression on supported remote-disk setups that do not have a coalescing filesystem-cache layer. Please fall back to the granule read unless the part is local or the remote read path is known to coalesce/cache readBigAt requests.
There was a problem hiding this comment.
If the underlying storage is not random read friendly AND there are no caches fronting this storage, then user can disable the setting. It would be a non-production deployment to go for a "slower" storage without a cache.
`readSegmentFromDisk` stopped advancing `fixed_size_lazy_row`, so every call continuing a mark range re-read the slice from the start of the range instead of from where the previous slice ended. Rows past the first slice were never filled and reached `L2Distance` as empty arrays: Code: 190. Array arguments for function arrayL2Distance must have equal sizes (SIZES_OF_ARRAYS_DONT_MATCH) The line sat next to `caches.clear()`, which master rewrote into a per-column clear loop, and it was dropped when resolving that conflict. Fixes the three Fast test failures in ClickHouse#123300 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This comment was marked as off-topic.
This comment was marked as off-topic.
The test was timing out due to a large number of rows. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| if (!isFixedPayloadSizeOneBlockPerRow( | ||
| data_part_info_for_read->getFileSizeOrZero(bin_path), data_part_info_for_read->getRowCount(), *row_bytes)) |
There was a problem hiding this comment.
❌ File size does not prove one block per vector
The promised ordinary read for existing parts can be bypassed by this check. Consider a Wide part written with quantized_vector_one_block_per_row = 0, Array(Float32) CODEC(Quantized('int8', 64)), and min_compress_block_size = max_compress_block_size = 300. Two vectors serialize to 512 payload bytes in blocks of 300 and 212 bytes. The element file is therefore (300 + 25) + (212 + 25) = 562 bytes, exactly 2 * (256 + 25), so isFixedPayloadSizeOneBlockPerRow accepts it after enabling the setting.
readFixedSizeLazyRowsByPosition then reads 281 bytes for row 0, while the valid first block needs 325 bytes. CompressedReadBuffer throws on the truncated block, and the enclosing reader reports the healthy part as broken. This breaks lazy rescoring over existing data when the setting is enabled.
Please establish the layout from a persisted per-column layout marker or verified block boundaries rather than total file size. Add a small stateless regression that writes the two-row part above with the setting off, enables it with ALTER TABLE, and checks that lazy rescoring still succeeds through the ordinary reader.
There was a problem hiding this comment.
We will disallow setting quantized_vector_one_block_per_row = 1 in ALTER TABLE
… layout `CompressedWriteBuffer` starts an adaptive buffer below `max_compress_block_size`, so the first block held less than one vector and shifted every row boundary after it. The element file then no longer measured `rows * (payload + 25)` and rescoring silently fell back to granule reads. The vector elements stream now opts out of adaptive sizing. Its two companion substreams keep it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… TABLE Whether a part stores one full-precision vector per compressed block is fixed when the part is written and is recorded nowhere, so a reader can only trust the layout if the table has had the setting from the start. Enabling it by `ALTER` over parts written without it left the reader addressing rows inside blocks that straddle row boundaries, which fails the read of a healthy part. `ALTER TABLE ... MODIFY SETTING quantized_vector_one_block_per_row = 0` stays allowed, as does the `RESET` that lands on a disabled default. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Master moved to 26.11 after this branch merged it, so the settings-history check wants the record of `quantized_vector_one_block_per_row` under the current version. The setting is new and has not shipped in 26.10, so the record moves rather than gaining a second entry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Trying alternate! |
Currently, during rescoring, we read and de-serialize a complete granule of full precision vectors, although we need only 1 or a few from that granule. Take a
k=100query with multiplier of 10 or more. We could end up reading 1000 granules of vectors. This PR only reads & deserializes the exact vector row we need. Note that the underlying storage read would be at whatever optimal size it is.Numbers
Code changes (excluding test files)
Changelog category
Changelog entry
Quantizedvector search rescoring on wide parts now point-reads only the shortlisted full-precision vectors instead of deserializing full granules.Workflow [PR]
Sync PR [sync-upstream/pr/123300]