Repository navigation
Fix a short read of the product quantization codebook - #112818
Merged
Merged
Conversation
The `product` method of the `Quantized` codec stores one codebook value for the whole part. It is written
once, in `serializeBinaryBulkStateSuffix`, after the data of all granules, so every granule's mark in the
`product_quantization_codebook` stream points at its start and no mark delimits its end.
`MergeTreeReaderStreamSingleColumn::getRightOffset` assumed the opposite. For a read whose mark range ends
before the end of the part it bounds the read at the offset of the first following mark with a greater
compressed offset. For the codebook stream that mark is the part's final mark, which is written right after
the suffix - and with an adaptive write buffer (starting at `adaptive_write_buffer_initial_size`, 16 KiB, and
doubling) the codebook spans several compressed blocks, so the final mark points into the middle of it. For a
64 KiB codebook the marks look like this:
mark 0..9 (0, 0) <- the data granules
mark 10 (49202, 16384) <- the final mark, inside the codebook
so the read was cut at compressed offset 49202 and threw
Cannot read all data of type FixedString. Bytes read:49152. String size:65536:
(while reading column vec.product_quantization_codebook)
The bound is only enforced by read buffers that implement `setReadUntilPosition` - object storage, encrypted
or cached disks - which is why this only showed up on the s3 CI runs, and only with a write-side
`min_columns_to_activate_adaptive_write_buffer` small enough to activate the adaptive buffer.
The codebook stream holds exactly one value for the whole part, so it must be read as a whole file, like the
metadata streams of `Dynamic` and `JSON`. This also repairs reads of parts that are already written.
Closes: #112804
Related: #110926
Contributor
|
Workflow [PR], commit [8dccc44] Summary: ✅
AI ReviewSummaryThis PR fixes a real wide-part Final Verdict
|
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code |
This was referenced Aug 1, 2026
shankar-iyer
approved these changes
Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #112804
Related: #110926
The
productmethod of theQuantizedcodec stores one codebook value for the whole part. It is written once, inserializeBinaryBulkStateSuffix, after the data of all granules, so every granule's mark in theproduct_quantization_codebookstream points at its start and no mark delimits its end.MergeTreeReaderStreamSingleColumn::getRightOffsetassumed the opposite. For a read whose mark range ends before the end of the part it bounds the read at the offset of the first following mark with a greater compressed offset. For the codebook stream that mark is the part's final mark, which is written right after the suffix - and with an adaptive write buffer (starting atadaptive_write_buffer_initial_size, 16 KiB, and doubling) the codebook spans several compressed blocks, so the final mark points into the middle of it. For a 64 KiB codebook the marks look like this:so the read was cut at compressed offset 49202 and threw:
The bound is only enforced by read buffers that implement
setReadUntilPosition- object storage, encrypted or cached disks - which is why this only showed up on the s3 CI runs, and only with a write-sidemin_columns_to_activate_adaptive_write_buffersmall enough to activate the adaptive buffer. That matches the two culprit settings the randomized-settings minimizer found in the issue.The codebook stream holds exactly one value for the whole part, so it must be read as a whole file, like the metadata streams of
DynamicandJSON. This also repairs reads of parts that are already written.The failing test is a plain
SELECTof the subcolumn, so this was not specific to it: any read of the codebook subcolumn whose mark range stops before the part's final mark could hit it. The new test reproduces that deterministically with aWHEREon the primary key, without the range-splitting injection - on alocal_blob_storagedisk, because a plain localReadBufferFromFileDescriptorignoressetReadUntilPositionand hides the bug.CI report from the issue: Stateless tests (amd_tsan, s3 storage, parallel, 3/3) (#111093)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Cannot read all data of type FixedStringwhen reading theproduct_quantization_codebooksubcolumn of a column with aQuantized('product', ...)codec. The per-part codebook is written after the data of all granules, so it is not delimited by marks, and a read whose mark range ended before the part's final mark could read it short.Version info
26.8.1.572(included in26.8and later)