{{ message }}
Preserve original key order in bucketed Map serialization#109178
Open
Avogar wants to merge 3 commits into
Open
Preserve original key order in bucketed Map serialization#109178Avogar wants to merge 3 commits into
Avogar wants to merge 3 commits into
Conversation
Bucketed Map serialization (PR #99200) splits map keys into buckets by hash, which reorders them. This breaks `ColumnMap::compareAt` (positional comparison) and operations that depend on it: ORDER BY, DISTINCT, GROUP BY, min/max, and equality filters on Map columns. Fix by writing an additional `MapBucketIndexes` substream during serialization that records each key-value pair's bucket index in original insertion order. During deserialization, this stream is used to reconstruct the original key order from per-bucket data. Key changes: - Add `SubstreamType::MapBucketIndexes` for the new stream - Add `CheckStreamExistsCallback` to `DeserializeBinaryBulkSettings` for backward compatibility with old parts lacking the stream - Update `SerializationMap`: write/read bucket indexes, implement `collectMapFromBucketsWithOrder` - Update `SerializationMapKeysOrValues`: same for `m.keys`/`m.values` subcolumn reads - Set `check_stream_exists_callback` in `MergeTreeReaderWide` and `MergeTreeReaderCompact` - Update existing test reference files for correct key ordering - Add stateless tests for key order preservation and comparison correctness - Add integration test for backward compatibility with old parts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
1 task
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.

Bucketed Map serialization (PR #99200) splits map keys into buckets by hash, which reorders them. This breaks
ColumnMap::compareAt(positional comparison) and operations that depend on it:ORDER BY, DISTINCT, GROUP BY, min/max, and equality filters onMapcolumns.Fix by writing an additional
MapBucketIndexessubstream during serialization that records each key-value pair's bucket index in original insertion order. During deserialization, this stream is used to reconstruct the original key order from per-bucket data.Key changes:
SubstreamType::MapBucketIndexesfor the new streamCheckStreamExistsCallbacktoDeserializeBinaryBulkSettingsfor backward compatibility with old parts lacking the streamSerializationMap: write/read bucket indexes, implementcollectMapFromBucketsWithOrderSerializationMapKeysOrValues: same form.keys/m.valuessubcolumn readscheck_stream_exists_callbackinMergeTreeReaderWideandMergeTreeReaderCompactChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Preserve original key order in bucketed Map serialization to fix comparison operations that depend on it.