Repository navigation
Do not claim that dictGetHierarchy is injective - #117357
Conversation
`dictGetHierarchy` returns an empty array for every key the dictionary does
not have, so two distinct absent keys collide on `[]` and the function is not
injective. The default-on `optimize_injective_functions_in_group_by` trusted
the claim, dropped the function from `GROUP BY` and grouped by the raw key
instead, so a query returned one `[]` row per absent key where the correct
answer is a single group:
SELECT dictGetHierarchy('d', k) AS h, count()
FROM (SELECT arrayJoin([toUInt64(100), toUInt64(200)]) AS k)
GROUP BY h;
-- two rows ([], 1) and ([], 1); the truth is one row ([], 2)
The claim would only hold for keys the dictionary has, where the returned
hierarchy starts with the key itself. `dictGetChildren` and
`dictGetDescendants` never claimed injectivity, and the `dictGet` family
forwards the user-declared `INJECTIVE` attribute flag, which is by design.
Closes: #117225
|
Workflow [PR], commit [fc0f2aa] Summary: ✅
AI ReviewSummaryThis PR fixes the actual bug in the implementation by stopping Findings
Final Verdict
LLVM Coverage ReportMeasured on commit fc0f2aa.
Changed lines: Changed C/C++ lines covered: 3/4 (75.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units11 translation units recompiled, 45 s compile time in total, 11 of them have a recent master baseline. |
…chy-not-injective-117225
…it 05087 -> 05099 The old-analyzer stateless job failed with `EXPLAIN QUERY TREE is only supported with the analyzer` (NOT_IMPLEMENTED) because the test used `EXPLAIN QUERY TREE` to assert that `dictGetHierarchy` is no longer eliminated from `GROUP BY`. Set `enable_analyzer = 1` right before that query; the result rows above it are still checked under both analyzers. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117357&sha=6fddd35aa8b23f9da036a5195964f7bd8aba312e&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%202%2F3%29 PR: #117357 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…chy-not-injective-117225
…limination in the test The old analyzer removes injective functions from `GROUP BY` in `TreeOptimizer`, independently of the query-tree pass, so the test now has absent-key `GROUP BY` and `uniqExact` cases with `SETTINGS enable_analyzer = 0`. On a binary without the fix they return one `[]` row per absent key.
|
🕵 The two stateless reds on 0b21535 are unrelated to this one-line
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117357&sha=0b215350b2cf3ee035eb4d9e4a8207c2283ee326&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29 ( The integration shard |
| SETTINGS enable_analyzer = 0; | ||
| SELECT dictGetHierarchy('d_hier', k) AS h, count() FROM (SELECT arrayJoin([toUInt64(100), toUInt64(200)]) AS k) GROUP BY h | ||
| SETTINGS enable_analyzer = 0; | ||
| SELECT uniqExact(dictGetHierarchy('d_hier', k)) FROM (SELECT arrayJoin([toUInt64(100), toUInt64(200), toUInt64(300)]) AS k) |
There was a problem hiding this comment.
The new uniqExact checks do not actually exercise the contract changed by this PR. Both uniq* injective-elimination paths only unwrap single-argument functions, so dictGetHierarchy('d_hier', k) is never simplified there because the constant dictionary name is still a second argument. These rows would stay green even on the pre-fix code.
The affected sibling surface here is LIMIT BY: OptimizeLimitByInjectiveFunctionsPass uses the same multi-argument unwrapInjectiveFunctionsInKeys helper as GROUP BY, so LIMIT 1 BY dictGetHierarchy('d_hier', k) would also return too many rows for absent keys before this fix. Please replace or supplement the uniqExact coverage with that case, plus an optimize_injective_functions_in_limit_by = 0 control query if you want the same ground-truth pattern.
|
The 04340 fix is in the PR you already linked. Besides the rethrow reorder, #118417 also changes Two things to add. The class-level fix is #105942, open since 2026-05-27 and approved by @ hanfei1991 on 2026-06-01: after each no-parallel/sequential test it disables whatever is still enabled in "Passed 3/3 reruns" is not evidence against the leak: the rerun is a separate On #118390: it removes the same trigger by a different route, giving the final result reader the query's cancellation so |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed
GROUP BY dictGetHierarchy(...)returning duplicate groups for keys that are absent from the dictionary.dictGetHierarchyis no longer declared injective.Documentation entry for user-facing changes
dictGetHierarchyreturns an empty array for every key the dictionary does not have, so two distinct absent keys collide on[]and the function is not injective. The default-onoptimize_injective_functions_in_group_bytrusted the claim, dropped the function fromGROUP BYand grouped by the raw key instead, so a query returned one[]row per absent key where the correct answer is a single group:The claim would only hold for keys the dictionary has, where the returned hierarchy starts with the key itself.
dictGetChildrenanddictGetDescendantsnever claimed injectivity, and thedictGetfamily forwards the user-declaredINJECTIVEattribute flag, which is by design.Closes: #117225
Workflow [PR]
Sync PR [sync-upstream/pr/117357]
Version info
26.9.1.879(included in26.9and later)