Repository navigation
Fix performance regression in short-circuit logical mask evaluation - #120520
alexey-milovidov merged 2 commits into
Conversation
Consume filtered logical argument results directly when updating the original row mask, preserving three-valued logic without expanding intermediate columns. Keep the full-sized result contract for generic masked execution used by `if` and `multiIf`. Add functional coverage for nullable and nested expressions, constants, shared arguments, filtered row positions, and skipped or required exceptions, plus performance cases for different mask densities. Related: ClickHouse#63723
|
Workflow [PR], commit [e4322ec] Summary: ✅
AI ReviewSummaryThis PR removes the extra full-block expansion in short-circuit Final Verdict✅ No new blocking or major issues found in the current diff. LLVM Coverage ReportMeasured on commit e4322ec.
Changed lines: Changed C/C++ lines covered: 65/68 (95.59%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes short-circuit evaluation of and/or. Later arguments now run only on rows that are still undecided, and their compact result feeds the mask directly instead of being expanded back to full block size. The only flagged query is ClickBench Q30, at -10.5% (214 ms vs 239 ms). It was correctly kept as no change: 214 ms is inside master's current range of 199-286 ms, CPU time is flat (2392 ms vs 2422 ms), and none of the standard ClickBench queries around Q30 has a multi-argument and/or filter. No regressions were found on clickbench or tpch_adapted_1_official; the new short_circuit_compact_logical_masks perf test is the right place to measure this change. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
This fixes a performance regression in short-circuit evaluation of
and/orintroduced by #63723 (commit4680d09e9a593524b85863acfbca421f0fb796a9). The unified execution path expands each filtered argument result back to the full block, then immediately scans it again to update the logical mask. The expansion is still present on upstream2dc8de96f8bcbc1721b337651bb7daffe15d9e9f.Consume the compact argument result directly while updating the mask at the original row positions. A separate null map preserves three-valued logic:
NULLkeeps a row active; a later decisive false forandor true fororoverrides it. GenericmaskedExecuteretains its full-sized result contract forif/multiIf, and the public mask extraction functions still reject incorrectly sized numeric columns.An isolated downstream 26.5-based comparison on an identical synthetic dataset and query reduced the cost of a four-way short-circuit predicate query:
Both candidates used 2,097,152 rows in 32 Wide parts,
max_threads=2, the same CPU affinity and memory limit, and stopped background merges. Each read 1,097,393 rows / 208,029,785 bytes and returned the same checksum. Other changes were held constant. This is downstream evidence motivating the patch, not an upstream-master or production-wide speedup claim; other tested queries had small improvements or regressions.Local verification: the new functional test and 11 existing short-circuit tests passed on both binaries in two runs each (48 test executions, zero skipped). The reference was generated from the baseline, agrees across
disable/enable/force_enable, and was independently checked against a scalar three-valued-logic oracle. Both expected division-by-zero exceptions and skipped exceptions were exercised.This local verification used the existing upstream Debug sandbox at
a8d7dcd970551b8664e08b64f8c4fcf5efa10fa7, with the three affected source files taken from the PR base for the matched baseline and then patched.MaskOperations.cpp/.hwere already identical to the PR base; interveningFunctionsLogical.cppchanges were documentation and exception wording. This is not a full build of current master; current-master CI remains to be run.Isolated Debug timings and CPU sampling
Clang 21.1.8, the same Debug build configuration,
max_threads=1,max_block_size=65536,compile_expressions=0, andshort_circuit_function_evaluation='force_enable'. Candidate order was A/B/B/A; each case ran 12 times per start, with the first two discarded. Values below are medians of 20 retained executions per binary. Every case read 1,000,000 rows and had matching result checksums. Elapsed time is measured by the localhost HTTP client; CPU isUserTimeMicroseconds + SystemTimeMicrosecondsfromsystem.query_log. These are synthetic diagnostics on a shared development host, without confidence intervals, not Release speedup claims.The mixed
orcase is reproducible with:Separately,
perf record -F 199 -e cpu-clock -g -p <server_pid>sampled repeated executions of the same case with 10,000,000 rows for about 20 seconds per binary (4,107 / 4,110 samples, zero lost samples):expandDataByMask<unsigned long>Only this logical-mask optimization differs between these two profiles. Missing a symbol at the report threshold is not proof of zero runtime; the lower independently measured query CPU supports the improvement. The source change removes expansion from this path while preserving it for generic masked execution.
The included performance test covers sparse, mixed, dense and nullable masks. The functional test covers all combinations of nullable logical inputs, nested
and/or/if/multiIf, shared expressions, constants,LowCardinality, empty and partial blocks, and throwing suffixes that must execute or be skipped.Related: #63723
Related: #114734
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a performance regression in short-circuit evaluation of
andandorby avoiding expansion of intermediate results that are only used to update the logical mask.Workflow [PR]
Sync PR [sync-upstream/pr/120520]
Version info
26.10.1.777-master(included in26.10and later)