Repository navigation
Conversation
…ey analysis The IN_RANGE branch of the sparse `KeyCondition::checkInHyperrectangle` (the default `use_lightweight_primary_key_index_analysis` path) copied the key range of its column for every atom, moved it through `applyMonotonicFunctionsChainToRange` even for an empty chain, and then ran the generic `Tuple` worklist of `hasNullOrNaNInside` twice. A filter with many comparisons on the key columns evaluates thousands of such atoms per query. Point at the key range and copy it only when the upper bound is widened or a non-empty chain is applied, as the non-sparse overload already does (eed8220), and answer a non-`Tuple` bound of `hasNullOrNaNInside` directly. The results are the same. `key_condition_multi_atom_wide_or` query #0 was red on Performance Comparison on several unrelated builds (official master 8112065, PR builds of ClickHouse#100394 and ClickHouse#102194): those builds run the same instructions in up to 2x the cycles, and the extra samples are in this loop. Locally (release, median of 30 x 5 rounds) its index analysis goes from 8.0 ms to 4.7 ms and its instructions drop by 20%. Related: ClickHouse#100394 (comment) 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; 0 findings) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261104-210700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261104-200900 |
|
cc @nihalzp @CurtizJ, could you review this and add the |
|
Workflow [PR], commit [f297b3d] Summary: ❌
AI ReviewSummaryPR #129381 removes redundant Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 25 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - f297b3dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261105-013005 |
Related: #100394 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Primary key analysis is faster for filters with many comparisons on the key columns (for example a long
ORof time ranges): the default lightweight analysis no longer copies the key range of a column for every comparison it checks.Description
Perf test
key_condition_multi_atom_wide_orquery #0 went red in this job of #100394 (+35.8%), and was reported slower on master (8112065) and on #102194 in the same two days. The PRs' own code is not involved: the slow builds run the same instructions in more cycles. The official binaries reproduce it on my machine at equal instruction counts: master 8112065 is 43% slower than the commit before it, and the #100394 build is 101% slower than its reference.Almost all of that query's time is primary key analysis in the default lightweight (sparse)
KeyCondition::checkInHyperrectangle. For every atom (about 120 per call here, thousands of calls per query), itsIN_RANGEbranch copied the key range of the column, passed it throughapplyMonotonicFunctionsChainToRangeeven when the chain is empty, and walkedhasNullOrNaNInsidethrough the genericTupleworklist twice.Now that branch points at the key range and copies it only to widen its upper bound or to apply a non-empty chain, as the other overload of this function already does.
hasNullOrNaNInsideanswers a bound that is not aTupledirectly. The sameFieldvalues are compared in the same order, so the results do not change. This does not remove the slow mode of some builds itself (all my local builds are in the fast one); it makes the loop that mode slows down about 40% cheaper.Validation: release build A/B from one tree, median of 30 runs, 5 rounds: query #0 index analysis 8.0 ms -> 4.7 ms (-42%), instructions -20%. Other perf tests:
key_condition_multi_expression_key-25%,primary_key_exclusion_search_non_key_conditions-20%,long_primary_keyandkey_condition_multi_atom_large_inunchanged. On a debug build the 172 key analysis tests pass (one PostgreSQL-protocol test could not run locally), and 37 of them pass 50 times with random settings.Workflow [PR]
Sync PR [sync-upstream/pr/129381]