Repository navigation
Apply optimizations to Nullable columns the same way as to non-Nullable - #125011
Conversation
…lable` Several optimizations were applied only to non-`Nullable` columns, which made `Nullable` columns much slower in NullableClickBench (ClickBench with all columns `Nullable`): - the `-Null` combinator did not forward `isParallelizeMergePrepareNeeded`, so the states of `uniqExact` over `Nullable` were not prepared for the parallel merge; - `length`, `empty`, `notEmpty` of `Nullable(String)` and the comparisons of `Nullable(String)` with an empty string were not rewritten to read the `size` subcolumn; - `sum(x + c)` was not rewritten to `sum(x) + c * count(x)` for `Nullable` `x`; - `empty` and `notEmpty` of a `Nullable(String)` key were not analyzed by the primary key, which is needed after the rewrite of the comparisons with an empty string. #124762 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [9551d18] Summary: ✅
AI ReviewSummaryThis PR extends several existing non- Final Verdict
|
|
📊 Cloud Performance Report ✅ AI verdict: This PR extends three query-tree rewrites to Nullable columns: the size-subcolumn rewrite for length/empty/notEmpty on Nullable(String), the sum(x + c) rewrite, and primary-key analysis of empty/notEmpty. It also makes the -If, -Null, -Array, -Merge and -State combinators pass isParallelizeMergePrepareNeeded through to the wrapped function. None of the flagged ClickBench or TPC-H queries reach this code: their columns are not Nullable and they use no combinators where this flag matters, so I downgraded the five improvements (ClickBench Q18, Q33, Q34 and TPC-H Q1, Q7) to not sure. In each of them the PR median is inside master's current range and the baseline sits at its slow end, which points to a slow baseline rather than a real speedup. ClickBench Q28 (-5.3%) stays not sure because the two tests disagree and the PR runs were noisy. clickbenchFlagged queries (4 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units26 translation units recompiled, 195 s compile time in total, 26 of them have a recent master baseline. |
…_fuse_sum_count` The reference now expects `sum(a + 1)` over `Nullable` `a` to be rewritten to `sum(a) + count(a)`, which depends on this setting, and the setting is randomized in CI. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125011&sha=latest&name_0=PR #125011 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… with an empty string `empty` and `notEmpty` of `Nullable(FixedString)` are not read from a subcolumn and not analyzed by `KeyCondition`, so the rewrite would lose the primary key analysis. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…`, `State`, `Array`, `Merge` combinators These adapters already forward `parallelizeMergePrepare` and `isAbleToParallelizeMerge` to the nested function, but returned the default `false` from `isParallelizeMergePrepareNeeded`, so e.g. `uniqExactIf` over a `Nullable` argument (built as `Null(If(uniqExact))`) still skipped the prepare step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failures: |
|
Neither is caused by this PR, and both already have a fix from me:
|
`ConvertEmptyStringComparisonToFunctionPass` rewrites `s = ''` to `empty(s)`. Since ClickHouse#125011 it does so for `Nullable(String)` too, and since ClickHouse#128092 for `LowCardinality(String)`, so comparisons of `Nullable(String)` typed paths and of `Dynamic` subcolumns such as `j.x.:String` with an empty string no longer reached the `equals` analysis of `jsonbf_v1`, and the index was not used for them. Analyze `empty` of a string like the comparison with an empty string, as `MergeTreeIndexBloomFilter` does. A missing non-`Nullable` typed path still reads as its default, which is not indexed, so `j.s = ''` for such a path keeps skipping the index. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113022&sha=c543bed2acf878e6046ff4920f52b901e3d77d7f&name_0=PR&name_1=Fast%20test PR: ClickHouse#113022 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
… = ''` `FunctionToSubcolumnsPass` rewrites `empty(s)`, which is what `ConvertEmptyStringComparisonToFunctionPass` makes of `s = ''`, to `s.size = 0`. Since ClickHouse#125011 both passes also apply to `Nullable(String)`, so `j.ns = ''` for a `Nullable(String)` typed path and ``j.x.:`String` = ''`` reach the index as `equals(j.ns.size, 0)` and ``equals(j.x.:`String`.size, 0)``, and `jsonbf_v1` was not used for them. The previous commit handled only `empty(s)`, which remains with `optimize_functions_to_subcolumns = 0`. Analyze the comparison of the size subcolumn of a `JSON` string subcolumn with zero as the comparison of the subcolumn with an empty string. A name that is itself a `JSON` path, such as a path whose last key is `size`, is not a size subcolumn. Verified locally: `05101`, `05102`, `05103`, `05106`, `05244` and `05497` pass. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113022&sha=c543bed2acf878e6046ff4920f52b901e3d77d7f&name_0=PR&name_1=Fast%20test PR: ClickHouse#113022 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01E5v7QTSR65LdYnQEv9HJVu
Several optimizations were applied only to non-
Nullablecolumns, and this madeNullablecolumns much slower than non-Nullableones in NullableClickBench (ClickBench with all columnsNullableand no NULLs):-Nullcombinator did not forwardisParallelizeMergePrepareNeeded, so the states ofuniqExactoverNullablearguments were not prepared for the parallel merge. Q5 (COUNT(DISTINCT UserID)): 0.113 sec. -> 0.057 sec.length,empty,notEmptyofNullable(String)and the comparisons ofNullable(String)with an empty string were not rewritten to read thesizesubcolumn. Q28 (AVG(length(URL)) ... WHERE URL <> ''): 0.176 sec. -> 0.039 sec.sum(x + c)was not rewritten tosum(x) + c * count(x)forNullablex. Q30 (90 sums ofResolutionWidth + k): 0.264 sec. -> 0.025 sec.emptyandnotEmptyof aNullable(String)primary key column were not analyzed byKeyCondition, which is needed after the rewrite of the comparisons with an empty string.The results for the non-
Nullabletable are the same as before (0.058, 0.034, 0.018 sec.).Related: #124762
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Queries over
Nullablecolumns use the same optimizations as over non-Nullableones:length,empty,notEmptyand comparisons with an empty string ofNullable(String)read thesizesubcolumn,sum(x + c)is rewritten tosum(x) + c * count(x), anduniqExactoverNullableis merged in parallel. This makes some queries several times faster.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125011]
Version info
26.10.1.2214-master(included in26.10and later)