Repository navigation
Fix single dictionary detection for multiple dicts in one mark interval - #105605
Conversation
|
Workflow [PR], commit [e595e6f] Summary: ❌
AI ReviewSummaryThis PR hardens Final Verdict
|
With this change the heuristic for single dictionary parts is fully validated, removing any ambiguity and any chance of false positives that previously resulted in rare (but unacceptable) occurrences of incorrect dictionaries being used. The added test fails before the changes and passes with the changes in place.
|
I rebased (for #105636) and added two commits:
I saw that you added |
0886f70 to
2662529
Compare
That's good, for some reason I thought we created 25.6 branch yesterday, thanks for noticing! |
…ream Avorgar's words: > It's not a good idea to rely on settings.getter to reset the stream. This callback > is used to just get the buffer for the stream, it doesn't guarantee the reset. Here we switch to using a callback for this purpose.
…m_marks_callback These are present for other callbacks, so they should be present for the new ones too.
2662529 to
e595e6f
Compare
LLVM Coverage Report
Changed lines: 84.13% (53/63) · Uncovered code |
da674ac
`MergeTreeReaderStream::hasAtMostNDistinctMarks` prefilters the single-dictionary decision for `LowCardinality` columns. It is documented as cheap, but it walks `marks_count` marks, which is the whole part's mark count rather than the range being read, once per `LowCardinality` column per read task. Its early exit only fires on a multi-dictionary part, so a genuine single-dictionary part, the case the optimization exists for, always paid the full scan. Marks are non-decreasing positions in the file, so equal marks form contiguous runs and the end of a run is one `std::upper_bound` away. Walk runs instead of marks: at most `max_transitions` binary searches, exact for any bound, with no precomputed state to store or invalidate. `getRightOffset` already did this search inline for the same `LowCardinality` dictionary stream, so both now share `findNextDifferentMark`. The check is only a necessary condition either way: `SerializationLowCardinality` still verifies it by reading the first dictionary and checking the stream reaches EOF, so the returned boolean and everything downstream are unchanged. Closes: ClickHouse#115998 Related: ClickHouse#105605 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Fixing up #103662 for good.
With this change the heuristic for single dictionary parts is fully validated, removing any ambiguity and any chance of false positives that previously resulted in rare (but unacceptable) occurrences of incorrect dictionaries being used.
The added test fails before the changes and passes with the changes in place.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Fixed single dictionary detection for multiple dicts in one mark interval (not present in any released version).
Note
Medium Risk
Changes LowCardinality deserialization behavior in MergeTree wide parts by adding stream reset/seek logic and stricter validation, which is correctness-critical and could affect reads if callbacks/stream positioning are wrong.
Overview
Fixes false positives in LowCardinality single-dictionary-per-part detection when multiple dictionaries are written within a single mark interval.
SerializationLowCardinality::deserializeBinaryBulkStatePrefixnow treatshas_uniform_marks_callbackas a prefilter only, then verifies single-dictionary parts by reading the first dictionary and requiringDictionaryKeysto be at EOF; if not at EOF it seeks the stream back to start (via a newseek_to_start_callback) so normal per-granule dictionary updates are read correctly.Plumbs the new
seek_to_start_callbackthroughISerialization::DeserializeBinaryBulkSettings, makesSerializationObject’s parallel prefix reading wrap the new callbacks safely, updatesMergeTreeReaderWideto implement the seek-to-start behavior, and adds a regression test04201_low_cardinality_multiple_dicts_single_markcovering the multi-dictionary-in-one-mark case.Reviewed by Cursor Bugbot for commit e595e6f. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.196