Repository navigation
Fix wrong results when reading several subcolumns of one column with the columns cache - #126298
Conversation
The subcolumn readers of one column share the deserialize states of their common streams (`Variant` discriminators, the structure of the `JSON` dynamic shared data, sparse offsets): the first reader in a call decodes such a stream and the others take it from the substreams cache without advancing their state. `DeserializationPrefixesCache` cloned every top-level state separately, so each reader got its own copy of a shared state, and `LowCardinality` never put its state into the states cache at all. When the columns cache serves a subcolumn for some granules and not for others, the decoding reader changes between calls and continues from a stale position: wrong values of `JSON` and `Variant` subcolumns, exceptions for `Dynamic` and `LowCardinality`. `DeserializeBinaryBulkState::clone` now memoizes the clones in a context shared by the whole prefixes map and calls the virtual `cloneImpl`, so a state shared before cloning stays shared after it. `LowCardinality` adds its state to the states cache in `deserializeBinaryBulkStatePrefix`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [65fd3dd] Summary: ✅
AI ReviewSummaryReviewed PR #126298 at Final VerdictStatus: ✅ Approve |
…states` `SYSTEM DROP COLUMNS CACHE` clears the columns cache of every test, and the test relies on its reads being admitted to the cache, which the adaptive admission makes probabilistic while other tests churn the cache. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126298&sha=9e3bb65ffe41a6341d7974629428332c2f6ff307&name_0=PR&name_1=Style%20check #126298 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
… thread fuzzer The insert parsed 400000 JSON values from text, and the parser of every value is taken from a pool under a mutex. With the thread fuzzer of the flaky check, which sleeps around mutex operations, the insert took about 450 seconds. Cast the JSON values from named tuples instead, which builds the same columns without parsing. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126298&sha=51847fa0d23fd23805a387c1a1fcfe2fa26cb755&name_0=PR&name_1=Stateless%20tests%20(amd_binary%2C%20flaky%20check) #126298 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es` once The cast from a named tuple to `JSON` goes through the text as well, so the insert still parsed a value per row and took about 230 seconds under the thread fuzzer of the flaky check. Parse a thousand values once and take them by index: the insert takes a fraction of a second. The values repeat every 1000 rows, which is not a multiple of the distance between the granules a stale decoder confuses, so without the fix the test still finds the wrong values (18928 of them for each `JSON` case). https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126298&sha=eebb6efc3b9&name_0=PR&name_1=Stateless%20tests%20(amd_binary%2C%20flaky%20check) #126298 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Status: the public CI for 3b1448c has no failed tests so far; some jobs are still running. The only red check is |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #126298 to 26.10: Fix wrong results when reading several subcolumns of one column with the columns cache
Conflicts, all context-only: - SerializationVariant.cpp, SerializationVariantElement.cpp: 26.8 has `clone()` without the clone context (ClickHouse#126298 is not in 26.8); keep it and add only the copies of the new `variant(s)_absent_in_storage` flags. - MergeTreeReaderWide.cpp: 26.8 has `addStream`, not `FileStreams::getOrCreate` (ClickHouse#114252 is not in 26.8); add only the new `isReadWithTypeInPart` before it. Semantic fix: `IMergeTreeReader::hasSubcolumnInPart` (ClickHouse#120632) is not in 26.8, so `isReadWithTypeInPart` uses `type->hasSubcolumn`, as the 26.8 readers already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts, all context-only: - SerializationVariant.cpp, SerializationVariantElement.cpp: 26.9 has `clone()` without the clone context (ClickHouse#126298 is not in 26.9); keep it and add only the copies of the new `variant(s)_absent_in_storage` flags. - MergeTreeReaderWide.cpp: 26.9 has `addStream`, not `FileStreams::getOrCreate` (ClickHouse#114252 is not in 26.9); add only the new `isReadWithTypeInPart` before it. Semantic fix: `IMergeTreeReader::hasSubcolumnInPart` (ClickHouse#120632) is not in 26.9, so `isReadWithTypeInPart` uses `type->hasSubcolumn`, as the 26.9 readers already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #96844
The subcolumn readers of one column share the deserialize states of their common streams through
SubstreamsDeserializeStatesCache: theVariantdiscriminators (also insideDynamic), the structure of theJSONdynamic shared data, the sparse offsets. In each read call the first reader decodes such a stream and the others take the result from the substreams cache without advancing their own state, which is correct only while they all hold the same state object.DeserializationPrefixesCache::clonePrefixescloned every top-level state separately, so each reader got a private copy of the shared state.LowCardinalitylooked its state up in the states cache but never inserted it, so its readers did not share it at all.Without the columns cache the same reader always decodes, so the copies never diverge. With
use_columns_cache = 1the columns cache serves a subcolumn for some granules and not for others, so the decoding reader changes between calls and continues from a stale position. The result is wrong values ofJSONdynamic paths andVariantsubcolumns without any exception,Unexpected format of compact discriminators granuleforDynamicsubcolumns, andInvalid type for SerializationLowCardinality index columnforLowCardinalityinsideTupleor aJSONtyped path.The fix:
DeserializeBinaryBulkState::cloneis now non-virtual. It takes aDeserializeBinaryBulkStateCloneContext, returns the clone made earlier in the same context if there is one, and otherwise calls the protected virtualcloneImpl.clonePrefixesuses one context for the whole map, so a state shared before cloning stays shared after it. Withcloneas the only public entry point, new states cannot bypass the memoization.SerializationLowCardinality::deserializeBinaryBulkStatePrefixadds its state to the states cache, as the other serializations with shared streams already do.The new test puts a part of the granules of one subcolumn into the columns cache with two primary key range reads, then reads it together with a sibling subcolumn under
PREWHERE. All 12 cases fail before the fix (4 with wrong values, 8 with exceptions) and pass with it.The columns cache appeared in #96844, so 26.10 needs the backport. Older releases clone the prefixes the same way but are not affected in practice: without the columns cache the decoding reader does not change.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix wrong values and the exceptions
Unexpected format of compact discriminators granuleandInvalid type for SerializationLowCardinality index columnwhen reading several subcolumns of the sameJSON,Variant,DynamicorLowCardinality-containing column withuse_columns_cache = 1.Workflow [PR]
Sync PR [sync-upstream/pr/126298]
Version info
26.11.1.193-master(included in26.11and later)26.10.2.19