Repository navigation
Make if with constant branches return LowCardinality - #80263
Conversation
|
Workflow [PR], commit [36137d6a] |
|
@alexey-milovidov it's kind of in shape in terms of compiling and tests... But it seems that the perf test for transform slowed down. (without to enum optimisation) Also... should this |
|
@jh0x, yes, it should be switchable with a setting. |
|
Workflow [PR], commit [25547bf] Summary: ✅
AI ReviewSummaryAdds opt-in Consumer coverage for the new representation:
Findings
Tests
Final VerdictStatus: |
@alexey-milovidov It has been done. |
…en they are strings The check whether the constant branches are identical materialized them as `Field` before checking the setting and the branch types, so it affected e.g. large constant arrays even with `optimize_if_transform_const_strings_to_lowcardinality = 0`. Compare the values only after the branches qualify for the `LowCardinality` optimization. Also validate the arguments of `if` with the declarative signature regardless of the optimization, so the error is the same either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pass update: merged current The two red jobs on
|
|
🕵 Pass update: merged current |
…ity` Disabling `useDefaultImplementationForLowCardinalityColumns` made `toBool` on an existing `LowCardinality(UInt64)` argument expand the dictionary, cast every row and re-encode the result, which was about 5x slower. Use `canBeExecutedOnDefaultArguments = false` instead: the default implementation then casts only the dictionary entries referenced by the rows, so the unused default entry (an empty string) does not throw, while invalid non-`NULL` values still do. Add a performance test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=80263&sha=e512d64cccc79172de6fa975808db1ce4cb648f9&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 ( |
|
The fix is already in progress: #128090 (mine, open, waiting for a review). This PR is not involved; the same abort happened twice on master ( The server log of this job:
|
|
🕵 Thanks, @groeneai. #128090 (still open) covers the Pass update: merged current |
| auto const is_string2 = isString(arguments[2].type); | ||
| if (is_string1 && is_string2) | ||
| { | ||
| result_type = std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()); |
There was a problem hiding this comment.
[Major] Preserve the arrayFold accumulator contract for inferred LowCardinality
The consumer compatibility changes still miss arrayFold, which disables the default LowCardinality handling and requires the lambda result to exactly equal the initial accumulator type (src/Functions/array/arrayFold.cpp:90-95). Inferring the new representation inside a lambda therefore breaks an otherwise valid fold:
SELECT arrayFold(
(state, x) -> if(state = 'found' OR x = 'b', 'found', 'searching'),
['a', 'b'],
'searching')
SETTINGS optimize_if_transform_const_strings_to_lowcardinality = 1,
optimize_if_transform_strings_to_enum = 0;Verified with this head's Fast test binary: setting 0 returns found; setting 1 throws TYPE_MISMATCH, reporting lambda result LowCardinality(String) versus accumulator String. The same failure occurs with multiIf and transform in the lambda. There is also the reverse mismatch: SELECT arrayFold((acc, x) -> concat(acc, x), ['a'], if(number % 2, 'b', 'c')) FROM numbers(2) now has a LowCardinality(String) accumulator but a String lambda result.
Please handle this at the fold's type/representation boundary, covering both the initial accumulator and the lambda result, or restrict inference so consumers requiring the old representation keep receiving it. Add focused stateless coverage with the setting off and on.
There was a problem hiding this comment.
This function should be adapted separately.
Master fixed `toBool` on a `LowCardinality` argument in ClickHouse#80263, so that statement no longer fails without this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master gained two key encoders that read a `Nullable` null-map byte as a value, and both must agree with the rest of this PR: - `HashedJoinKey::buildRows` (ClickHouse#129328) copies the bytes that `hash128` hashes, and its own contract is that every way of building a key gives exactly `hash128`. This PR makes `ColumnNullable::updateHashWithValue` hash `byte != 0`, so after the merge the copied raw byte broke that contract: on the merged tree `SELECT count() FROM t l JOIN t r ON l.s <=> r.s` over a Native null map with bytes 0, 1 and 2 aborts on the debug check in `buildRange` (AVX2 and NEON builds). It now copies `byte != 0`: 500 rows, where master gives 300. - `encodeFixedSizeKeys` (ClickHouse#124907) packs NULL into a one-bit field, so a byte 2 set the lowest bit of the column before it. With `transform_null_in = 1` and a set spilled to disk, `(0, NULL)` was found in `{(1, 0)}`: master 10 rows, 0 in memory. The right side is read back from the canonical in-memory keys, so only the probe side carried the raw byte. Both are bit-identical on 0/1 maps. 05210 covers both cases, and gains a `groupUniqArray(tuple(s))` case for the arena key encoder (`serializeValueIntoArena`), which no case reached: reverting it left 05210 green, now it gives 3 keys where 2 are correct. 05210 also pins `optimize_if_transform_const_strings_to_lowcardinality` to 0: the runner randomizes it since ClickHouse#80263, and with it `if` returns `LowCardinality(Nullable(String))`, which has no `.null` subcolumn, so the `if` case failed with UNKNOWN_IDENTIFIER on half the runs. 05211 is removed: ClickHouse#129812 made the Iceberg null count use `countBytesInFilter`, so that reader is master's now and the merge drops it from this PR (05211 passes on master). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #25272
Add the opt-in
optimize_if_transform_const_strings_to_lowcardinalitysetting. When enabled,if,multiIf, andtransforminferLowCardinality(String)from constant string result branches. The default remains disabled because per-block dictionary construction can regress workloads without downstream dictionary reuse.Also make affected consumers accept the inferred type, including IP parsing,
toBool, time-zone arguments,Prometheuslabels, anddefaultValueOfTypeName.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add an opt-in optimization for
if,multiIf, andtransformwith constant string arguments to useLowCardinality.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/80263]
Version info
26.11.1.1726-master(included in26.11and later)