Repository navigation
Optimize bucketed LowCardinality map reconstruction - #107434
EmeraldShift wants to merge 1 commit into
Conversation
|
I actually probably didn't mind if Map(LC(Key), ..) would use shared dictionary for all buckets, but probably now it's too late to do that. Do you somehow use that fact, that for LC(key), because map is sharded, it's guaranteed that values will not intersect. shared_dict_id = dict_id * NUM_BUCKETS_IN_SELECT + bucket_id; -- |
|
Workflow [PR], commit [74ad91e] Summary: ❌
AI ReviewSummaryThis PR replaces the per-slice Final Verdict
|
7731f93 to
e2937e2
Compare
e2937e2 to
cf1b204
Compare
|
📊 Cloud Performance Report ✅ AI verdict: This sync PR changes only bucketed Map reconstruction when keys/values are LowCardinality (a new SerializationMapLowCardinalityBuckets fast path). ClickBench has no Map(LowCardinality) columns, so neither Q4 (-13.7%) nor Q15 (-13.1%) can be affected by it. Both apparent improvements land inside master's current variance band and were correctly held at no_change; they are off-path run-to-run variance, not a real effect of this change. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
cf1b204 to
74ad91e
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 73/74 (98.65%) · Uncovered code |
|
Dear @Avogar, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Reading a bucketed
Mapback as a full map has to stitch the per-bucket streams back into row order. Before this change, aLowCardinalitykey or value column used the generic insertion path for each small row/bucket slice. Each of those tiny inserts had to translate source bucket dictionary indexes into the destination dictionary, so the read paid the dictionary-remapping overhead over and over again.This keeps the same logical reconstruction order, but does the
LowCardinalityremapping in bulk. Each bucket is first represented as a compact dictionary plus indexes. The bucket dictionaries are concatenated into a temporary dictionary, a single row-ordered index stream is built, and that temporary dictionary-encoded stream is merged into the outputColumnLowCardinalityonce.The same helper is used for full
Mapreconstruction and formapKeys/mapValuesbucket reassembly. In fullMapreconstruction, the helper is tried independently for keys and values, so it handlesMap(LowCardinality(K), V),Map(K, LowCardinality(V)), andMap(LowCardinality(K), LowCardinality(V)). The first successfulLowCardinalitycollection also builds the shared map offsets from bucket lengths; when both streams are collected, the old row/bucket insertion loop is skipped entirely.The temporary dictionary is only an intermediate representation.
insertRangeFromDictionaryEncodedColumnstill inserts into the destination dictionary using the normalColumnLowCardinalitypath, so unexpected duplicate temporary dictionary values remain correct. In the expected bucketed-map case, keys should be disjoint across buckets because bucket assignment is deterministic by key.Local benchmark details:
clickhouse localwith--print-profile-events --profile-events-delay-ms=-1. CPU numbers areOSCPUVirtualTimeMicrosecondsmedians; lower is better. The main benchmark uses 50k rows, 200 keys/row, and 32 buckets.Bucketed reconstruction, true baseline vs current patch:
Map(LC(String), String)Map(LC(String), String)mapKeysMap(LC(String), String)mapKeys+mapValuesMap(String, LC(String))Map(String, LC(String))mapValuesMap(String, LC(String))Map(LC(String), LC(String))Map(LC(String), LC(String))mapKeys+mapValuesQuery-shape comparison against non-bucketed/basic serialization for
Map(LowCardinality(String), String):Non-
LowCardinalitysanity check from the same run. These paths continue through the existing generic insertion path:Map(String, String)Map(String, String)mapKeysMap(String, String)mapValuesThe optimization narrows the full-map regression of bucketed
Map(LowCardinality(...), ...)reads while preserving the main benefit of bucketed maps: reading one or many specific keys without the full map remains much faster than basic serialization.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Optimized loading
LowCardinalitydata when readingmapKeys(m),mapValues(m), or the whole map, when using the bucketed map serialization.