Repository navigation
Conversation
…over `String` `if(cond, s, t)` with a `String` result and a `String` column in a branch goes through `GatherUtils::conditional`, which handles one row per step: it grows the result, branches on the condition and copies the row with the 16-byte small-copy loop. For two `String` sources, at least one a column, `conditional.cpp` reads the condition 64 rows at a time. A group with few runs of equal conditions is copied run by run: the rows of a run are contiguous in the source they take, so the run is one copy and its offsets are the source's, shifted. Other groups are written row by row into the reserved result, with a branch on the condition when it alternates (predictable) and without one otherwise. Other sources and sinks are unchanged. Analysis and patch: ClickHouse#130929 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the same branch Co-Authored-By: Claude Opus 5.5 <[email protected]>
…over `String` For `begin == 0` the size_t index `begin - 1` wrapped the raw offsets pointer by SIZE_MAX. The address is the intended `offsets[-1]` (the zero in the left padding), but UBSan reports the pointer overflow and aborts. The machine code of the release build is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`tests/performance/scripts/README.md` says queries over a `Memory` table bigger than 1 GB can be unstable. Split the two tables into four, by the columns each query reads, and give the 65-byte pair 3M rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the comments of conditional over String to the invariants a reader needs: the 64-row grouping, why alternating groups branch, constant sources read row 0 of a padded column, the one-byte reserve and the 15-byte overwrite. Removed rationale: like the generic conditional, the result reserves the larger source and grows; every row copies at least one byte so empty and short strings take one path; long runs come from conditions like CASE WHEN c THEN s ELSE '' END, while alternating or random conditions give one- or two-row runs that are cheaper to copy row by row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261114-222800 |
|
cc @antaljanosbenjamin, could you review this? It adds non-template GatherUtils::conditional overloads for String sources (at least one a column) that read the condition 64 rows at a time, copy a group with at most 16 runs of equal conditions one run per copy, and write other groups row by row into the reserved result, which makes if over String columns faster. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261114-221800 |
|
Workflow [PR], commit [485ba9b] Summary: ✅
AI ReviewSummaryPR #131699 specializes Final VerdictStatus: ✅ Approve |
In `Stateless tests (amd_asan_ubsan, flaky check)` the test ran 230-247 s per run (cap 180 s), and 140-165 s in the amd_binary and amd_debug legs. The job's query_log puts 150 s of each run in the `max_block_size = 1` query and 83 s in the four `max_block_size = 7` queries: the cost is the number of blocks, one pipeline handoff per 1 or 7 rows over 10000 rows. The queries with blocks of 1 and 7 rows now read 50 of every 500 rows (`n % 500 < 50`, 1000 rows). That keeps every region of the view: all condition patterns and values 0/1/2/255, all 97 string lengths, empty and non-empty strings. The filter is applied right above `ReadFromSystemNumbers`, and `if` still sees blocks of 1 row and of 1..7 rows (`blockSize()`). The queries with blocks of 1000 rows are unchanged. Same oracle: the new reference is the output of a master build, and the fix's output is identical to it, with every `countIf(r != ref)` = 0. The four mutations of the kernel (column run offset, both row-path source swaps, constant run copied once) redden exactly the same output lines as before. ASan, 50 runs at 8 workers on 16 CPUs: p50 11.26 s -> 2.57 s, max 12.67 s -> 3.27 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A group of 64 rows with more than 16 runs of equal conditions is copied row by row without a branch. On Graviton 3 (Neoverse V1) that is slower than master for long rows with short runs: measured by @ snelheidai in ClickHouse#130929 (comment) (`SELECT count() FROM t WHERE NOT ignore(<expr>) SETTINGS max_threads = 1`, 6 rounds, ratio to master): 64 B in runs of 2 rows 1.278, 128 B in runs of 2 rows 1.755, 64 B in runs of 3 rows 1.262. On aarch64 a group whose column sources average at least 64 bytes per row is now copied run by run, which gives 0.684, 0.786 and 0.644 there; no measured shape is slower than master (closest: random 128-byte rows, 0.890), random 65-byte rows go from 0.781 to 0.871, and `if(c_nat, Referer, '')` from 0.680 to 0.440. x86 does not use the rule: the release object of `conditional.cpp` has an identical disassembly before and after this change (forcing the rule on changes 5413 lines of it). There the rule cost random runs of 4 rows of 65 bytes 1.188 [1.055, 1.338] against the kernel without it, as the long-string rule of the ClickHouse#130929 kernel did before (1.110 against master). Verified on x86 with the rule forced on (`#if 1`): `05768_if_string_runs` output identical to the reference on debug and ASan+UBSan builds (no sanitizer report), and a path probe shows the new run-by-run groups for column/column, column/constant and constant/column (48/49/16 groups) while row-by-row groups remain. For aarch64: `-fsyntax-only -Werror` with the cross flags is clean (an `#error` in the aarch64 branch fires, so that branch is the one compiled), and clang-tidy-22 reports nothing. `if_string_runs.xml` gets 64-byte strings in runs of 2 rows (5M rows, 693 MiB), the shape the aarch64 performance comparison needs to see this. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`if(c_rand, 'x', Referer)` takes the constant/column overload (the one `ifNull` reaches through `if(isNull(x), y, assumeNotNull(x))`), which no query of the performance test covered. x86: 0.864 [0.848, 0.880] of master (6 rounds, 10M rows); Graviton 3 (ClickHouse#130929): 0.778, 0.677 with the aarch64 rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 91fa9c6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261115-053020 |
The Iceberg configuration of the performance comparison widens the `UInt8` condition columns of the test's tables to `Int32`, and `if` rejects an `Int32` condition (`Arguments of function if do not match its signature ... value provided as 1st argument has type Int32 that is not MaybeNullable(UInt8)`), so the six `Performance Comparison (arm_release, master_head, iceberg_local|iceberg_s3, N/3)` jobs, which run only the changed test, failed on every query. Even if it ran, the test would measure the conversion of the condition rather than the `UInt8` path it is about. `<test iceberg="0">` drops the test from the configuration (`test_runs_with_table_engine` in `ci/jobs/scripts/perf/test_discovery.py`), so those jobs are not scheduled for this pull request. The skip list is not used: `tests/performance/iceberg_skip_list.txt` is one of `ICEBERG_PERFORMANCE_PATHS`, so changing it would run the whole Iceberg suite. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes11 object files changed (+8.93 KiB total), 1 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units31 translation units recompiled, 182 s compile time in total, 30 of them have a recent master baseline. |
Closes: #130929
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ifwith aStringresult is faster when a branch is aStringcolumn, also forCASEwith a singleWHEN. Single-threaded on x86, evaluatingif(c, MobilePhoneModel, 'unknown')with a random condition is 2.8x faster, and evaluating theCASEof ClickBench Q39 is 1.4x faster.Description
GatherUtils::conditionalhandles one row per step: it grows the result, branches on the condition and copies the row. The newGatherUtils/conditional.cppaddsconditionaloverloads for twoStringsources (at least one a column) into aStringSink. They read the condition 64 rows at a time (bytes64MaskToBits64Mask). A group with at most 16 runs of equal conditions is copied run by run: one copy per run, whose offsets are the source's, shifted. Other groups are written row by row into the reserved result, with a branch when the condition alternates (predictable) and without one otherwise.if.cpp,multiIf,FixedStringand constant/constant are unchanged.On aarch64 a group whose column sources average at least 64 bytes per row is also copied run by run: on Graviton 3 this takes 64- and 128-byte strings in runs of 2 rows from 1.28 and 1.76 of master to 0.68 and 0.79 (#130929). x86 does not use it: the #130929 kernel, which has it, made 65-byte strings in short runs slower than master (up to 1.110 [1.042, 1.182]); without it none of 78 shapes is significantly slower (closest: 1.048 [0.999, 1.099]).
x86 (Xeon 6975P-C),
SELECT count() FROM t WHERE NOT ignore(<expr>) SETTINGS max_threads = 1, 10M rows, 6 rounds, ratio = PR / master [95% CI]:if(c_nat, Referer, '')(Q39's condition) 0.718 [0.682, 0.755],if(c_64, Referer, '')0.618 [0.587, 0.652]if(c, SearchPhrase, '')0.509,if(c, MobilePhoneModel, 'unknown')0.353,if(c, s16, t16)0.531sum(cityHash64(...))of 80 expressions)Tests:
05768_if_string_runschecks every path (column/column, column/constant, constant/column, tail groups, growth past the reserve,Nullable,CASE) against anarrayElementoracle;if_string_runs.xmlhas the gain shapes, the ones a first version made slower, and 64-byte strings in runs of 2 rows.Workflow [PR]
Sync PR [sync-upstream/pr/131699]