Skip to content

Bound the query-analysis cost of optimize_and_compare_chain (and the lambda-resolution recursion guard) - #108757

Merged
alexey-milovidov merged 9 commits into
masterfrom
optimize-lambda-resolve-recursion-guard
Jul 1, 2026
Merged

alexey-milovidov merged 9 commits into
masterfrom
optimize-lambda-resolve-recursion-guard

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 28, 2026 •

Copy link
Copy Markdown
Member

Link to ray tracer: https://github.com/ClickHouse/RayTracer

Query analysis can be dominated by IQueryTreeNode::getTreeHash for queries whose WHERE/HAVING contain many or very large AND-chains of comparisons. getTreeHash is an uncached, whole-subtree walk, and two analyzer sites call it once per node over big subtrees, so the cost grows with the size of the expression tree rather than the data.

This surfaced in an extreme way on a SQL ray tracer (a single SELECT built from ~30 nested lambdas and arrayFold, whose comparison operands are huge let-expanded expressions): even a 16×16 image spent ~72 s in query analysis, ~80 % of it in getTreeHash. Profiling traced it to two places, fixed here:

1. optimize_and_compare_chain (LogicalExpressionOptimizerPass::tryOptimizeAndCompareChain). It groups AND-chain comparisons using QueryTreeNodePtrWithHash containers, each of which eagerly computes the full tree hash of the operands/conjuncts. On a scene with many large AND validity checks it hashes a large fraction of the (already huge) tree for every AND node, while typically folding nothing. It is now bounded by a work budget measured directly in nodes hashed: getTreeHash accumulates the number of nodes it visits into a thread-local counter, and the visitor stops the optimization for the rest of the query once it has hashed more nodes than the budget. Counting inside the hash walk measures the real cost without a separate tree-size pass. Stopping early is always safe — it only forgoes an optimization, never changes results. The budget is checked at the entry of the optimization, while collecting comparison operands and existing conjuncts (the map/set-building phase, where each insert hashes an operand), and inside the DFS, so a single very large AND chain cannot hash its whole operand set before the cap applies. The budget is exposed as the new setting optimize_and_compare_chain_max_hash_work (default 5000000; 0 disables it).

2. QueryAnalyzer::resolveLambda recursion guard. This guard (lambdas_in_resolve_process) must detect re-entry by structure, not by pointer identity: a recursive lambda reference resolves to a fresh clone of the alias node (tryResolveIdentifierFromAliases clones the alias body), so the recursive node is only structurally equal to the one being resolved, never the same pointer. It therefore stays a QueryTreeNodePtrWithHashSet, but the original performance problem — every find/emplace/erase recomputing the full tree hash of the (un-cloned) lambda body — is fixed by computing that hash only once per resolveLambda call: a single QueryTreeNodePtrWithHash is built and reused for the contains/insert/erase.

Effect on the ray-tracer (16×16, default settings): query analysis ~72 s → ~3 s, byte-identical output. Normal queries hash only thousands of nodes, never reach the budget, and are unaffected (verified the transitive-comparison derivation still fires, and that recursive WITH-lambdas still throw UNSUPPORTED_METHOD).

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Sped up query analysis for queries with many or very large AND-chains of comparisons: the optimize_and_compare_chain optimization is now bounded by a work budget (new setting optimize_and_compare_chain_max_hash_work) instead of hashing a large fraction of the query tree, and lambda resolution no longer recomputes lambda-body hashes for its recursion guard.

alexey-milovidov and others added 2 commits June 28, 2026 15:50
…not tree hash)

QueryAnalyzer::resolveLambda used `lambdas_in_resolve_process`, a
QueryTreeNodePtrWithHashSet, as a recursion guard. QueryTreeNodeWithHash eagerly
computes the full IQueryTreeNode::getTreeHash (a complete, uncached walk of the
lambda body subtree) on every find/emplace/erase. For queries with many large
lambdas this dominates query analysis: profiling a 173-lambda expression showed
~80% of analysis time in getTreeHash, all under resolveLambda.

The guard only needs to detect re-entry into the same (original, un-cloned)
lambda node; a recursive reference resolves to the same alias node, so node
pointer identity is sufficient and correct. Switched the set to
std::unordered_set<const IQueryTreeNode *>. This also removes a latent risk of a
false "Recursive lambda" error on two structurally-identical lambda nodes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LogicalExpressionOptimizerPass::tryOptimizeAndCompareChain groups AND-chain
comparisons using QueryTreeNodePtrWithHash containers, each of which computes a
full (uncached) IQueryTreeNode::getTreeHash of the operands/conjuncts. On queries
with very many or very large AND-comparison chains (e.g. a SQL ray tracer whose
operands are big let-expanded expressions) this hashes a large fraction of the
query tree for every AND node and dominates query analysis -- a 16x16 render
spends ~72s in analysis -- while typically folding nothing.

Bound it by the actual hashing work: getTreeHash now accumulates the number of
nodes it visits into a thread-local counter, and the visitor snapshots that
counter at start and stops the optimization for the rest of the query once it has
hashed more than 5M nodes. Counting inside getTreeHash measures the real cost
directly, so no separate tree-size estimation is needed. Stopping early is always
safe -- it only forgoes an optimization, never changes results.

Effect (16x16 SQL ray-trace, default settings): analysis ~72s -> ~3s (~24x),
byte-identical output. Normal queries hash only thousands of nodes, never reach
the budget, and are unaffected (verified the transitive-comparison derivation
still fires). The threshold could later be exposed as a setting.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [01a56fe]

Summary: ✅


AI Review

Summary

This PR bounds optimize_and_compare_chain hashing with the new optimize_and_compare_chain_max_hash_work setting and keeps resolveLambda recursion detection structural while avoiding repeated hash construction. The prior map-building budget and compatibility-history issues are fixed in the current code, and I did not find remaining correctness, compatibility, or safety blockers.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR only changes query-analysis behavior: it adds a work budget to the optimize_and_compare_chain optimization (which only matters for queries with very large AND-chains of comparisons) and reuses a lambda-resolution hash. ClickBench Q4, Q15, and Q28 have simple WHERE clauses and no lambdas, so they never hit the budget or the lambda path, and analysis time is a tiny fraction of their runtime. The flagged 15-16% improvements on Q4/Q15 and 5% on Q28 are too large to come from an analyzer micro-optimization on queries that don't exercise it, so all three were downgraded to not-sure as off-path variance. No regressions were found.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 4 not_sure 263 221 -16.0% <0.0001 plan_change: Analyzer-only AND-chain budget change; Q4 has no large AND-chains or lambdas, so 16% delta is off-path variance
⚠️ 15 not_sure 236 200 -15.2% <0.0001 plan_change: Same analyzer-only change; Q15 group-by/order-by exercises no AND-chains or lambdas, improvement is run-to-run noise
⚠️ 28 not_sure 6678 6320 -5.3% <0.0001 plan_change: Analyzer budget/lambda tweak doesn't touch Q28 regex+aggregation execution; 5% on a 6.3s query is variance

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_official

🟢 No significant changes

Debug info
  • StressHouse run: 225403ea-84f4-49cc-837e-46ac49234dad
  • MIRAI run: bc2a3f33-dafe-4e69-8439-3bd495729342
  • PR check IDs:
    • clickbench_549369_1782860180
    • clickbench_549383_1782860180
    • clickbench_549389_1782860180
    • tpch_adapted_1_official_549396_1782860180
    • tpch_adapted_1_official_549406_1782860180
    • tpch_adapted_1_official_549419_1782860180

alexey-milovidov and others added 5 commits June 28, 2026 23:47
The previous commit changed `lambdas_in_resolve_process` to a
`std::unordered_set<const IQueryTreeNode *>` keyed by pointer identity.
That is incorrect: a recursive lambda reference resolves to a *fresh
clone* of the alias node (`tryResolveIdentifierFromAliases` clones the
alias body), so the recursive node is only structurally equal to the one
being resolved, never the same pointer. With pointer identity the guard
never fires for genuine recursion, and the query instead recurses until
`TOO_DEEP_RECURSION`. This regressed `02388_analyzer_recursive_lambda`
and `02343_analyzer_lambdas`, where recursive `WITH`-lambdas are expected
to throw `UNSUPPORTED_METHOD` (`Recursive lambda`).

Restore the structural-hash guard (`QueryTreeNodePtrWithHashSet`) so
recursion is detected correctly, but address the original performance
problem by computing the lambda's tree hash only once per `resolveLambda`
call: a single `QueryTreeNodePtrWithHash` is built and reused for the
`contains`/`insert`/`erase`, instead of constructing a fresh one for each
operation (which recomputed the full `getTreeHash` three times).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review feedback from `clickhouse-gh`: the work-budget check only
guarded the entry of `tryOptimizeAndCompareChain` and the DFS in
`findPairs`, but the map-building phase between them inserts every
comparison operand into `QueryTreeNodePtrWithHash` containers (and the
existing conjuncts into a `QueryTreeNodePtrWithHashSet`), each insert
computing a full `getTreeHash`. For a single very large `AND` chain that
phase could hash the whole operand set before any later budget check, so
the cap did not apply to exactly the "many or very large `AND`-chains"
case it targets.

Check the budget while collecting `greater_pairs`/`less_pairs` and
`existing_conjuncts` and abort as soon as it is crossed. Aborting there is
safe -- no conjunct has been appended to the `AND` yet, so the
optimization is merely skipped and results are unchanged. The repeated
condition is factored into a small `andCompareChainHashBudgetExceeded`
helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `optimize_and_compare_chain` work budget was a hard-coded 5M constant,
which made it impossible to exercise the budget back-off path in a fast,
deterministic functional test (triggering it otherwise needs a multi-megabyte
query). Expose it as the new setting `optimize_and_compare_chain_max_hash_work`
(default `5000000`, `0` disables the budget), as the PR description anticipated.

The visitor now reads the budget from the setting instead of the constant, and
`andCompareChainHashBudgetExceeded` treats `0` as unlimited so the optimization
is never stopped early in that case. Behavior is unchanged at the default.

Add `04490_optimize_and_compare_chain_work_budget`: it asserts that a large
`AND`-chain of comparisons returns identical results across the default budget,
a budget of `1` (which forces the optimization to back off, including during
operand collection), an unlimited budget, and the optimization disabled -- the
budget only forgoes redundant derived predicates, never changes results. It
also asserts, via `EXPLAIN QUERY TREE`, that a large budget expands the
transitive chain (more `less` comparisons) than a budget of `1`, proving the
budget actually controls whether the optimization fires.

This addresses the `clickhouse-gh` AI review "Request changes": the budget now
provably covers the map/set-building phase and there is focused, deterministic
evidence for the pathological `AND`-chain case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed updates addressing the failing Fast test and the AI review ("Request changes"):

  • Fast test failures (02388_analyzer_recursive_lambda, 02343_analyzer_lambdas) fixed. The earlier change keyed the resolveLambda recursion guard on pointer identity, but a recursive lambda reference resolves to a fresh clone of the alias node, so the guard never fired and genuine recursion ran until TOO_DEEP_RECURSION instead of UNSUPPORTED_METHOD. The guard is back to the structural QueryTreeNodePtrWithHashSet, but the hash is computed only once per resolveLambda call (one QueryTreeNodePtrWithHash reused for contains/insert/erase) — keeping the speedup without the regression. Verified on the built binary: all four recursive-WITH-lambda cases now throw Recursive lambda … (UNSUPPORTED_METHOD).
  • Budget now covers the map/set-building phase of tryOptimizeAndCompareChain (the operand-collection loop and existing_conjuncts), not just the entry and DFS.
  • Budget exposed as the setting optimize_and_compare_chain_max_hash_work (default 5000000, 0 = unlimited), and added focused test 04490_optimize_and_compare_chain_work_budget: it forces the back-off with a budget of 1 and asserts results are identical to the default/unlimited/disabled cases, and that a large budget expands the transitive chain more than a budget of 1.
  • Merged fresh master and updated the PR description (which had described the reverted pointer-identity approach).

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
…in_max_hash_work

The `SettingsChangesHistory.cpp` entry for the new
`optimize_and_compare_chain_max_hash_work` setting recorded `5'000'000` as
both the previous and the new value. Before this setting existed the
`optimize_and_compare_chain` optimization was uncapped, which this PR
defines as `0` (unlimited). Recording the previous value as `5'000'000`
meant `SET compatibility = '26.6'` kept the new cap instead of restoring the
old behavior, so compatibility mode could still stop deriving transitive
predicates for huge `AND` chains.

Record the previous value as `0` so `compatibility` set to a pre-26.7
version reproduces the original uncapped behavior. Extend
`04490_optimize_and_compare_chain_work_budget` with an assertion that
`compatibility = '26.6'` reverts the budget to `0`.

Addresses the AI review finding on `SettingsChangesHistory.cpp`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed 7074a41 addressing the AI review's only "Request changes" finding (SettingsChangesHistory.cpp).

What changed. The history entry for the new optimize_and_compare_chain_max_hash_work setting recorded 5'000'000 as both the previous and the new value. Before this PR the optimize_and_compare_chain optimization was uncapped — equivalent to 0 (unlimited) — so SET compatibility to a pre-26.7 version must restore 0, not keep the new cap. The entry now records 0 → 5'000'000. Verified on a freshly built binary:

SELECT value FROM system.settings WHERE name = 'optimize_and_compare_chain_max_hash_work' SETTINGS compatibility = '26.6';  -- 0
SELECT value FROM system.settings WHERE name = 'optimize_and_compare_chain_max_hash_work';                              -- 5000000

Added that assertion to 04490_optimize_and_compare_chain_work_budget (passes), and confirmed 02995_new_settings_history still detects nothing new (the setting stays recorded under 26.7). Resolved the corresponding review thread.

Remaining red — CH Inc sync ("tests failed") is unrelated to this PR. The sync PR (#62533) is MERGEABLE and builds cleanly; the failures are private-CI flakes/infra in code paths an analyzer-only change cannot reach (and the equivalent public jobs are green):

  • Integration (db disk, old analyzer, 5/7): test_dictionaries_postgresql::test_invalidate_query (dictionary-reload value race) and test_refreshable_mv_attach_without_multi_read (refreshable-MV status timing) — two independent flakes. These run with enable_analyzer=0, where none of this PR's new-analyzer code executes.
  • Integration (db disk, old analyzer, 7/7): all 7 failures are test_shared_set_join — minio/cluster failed to start (wait_minio_to_start Connection refused), cascading into Table ... already exists. Pure infra.
  • Stress (arm_asan_ubsan, SharedCatalog, meta in keeper): a logical-error abort Current component is empty, please set it ... Coordination::setCurrentComponent (STID 2884-409a) entirely in the private SharedCatalog Keeper metadata path (MetadataStorageFromKeeper ← ReadFromMergeTree::buildIndexes), zero analyzer frames. Pre-existing and PR-unrelated.

None of the failure output references optimize_and_compare_chain, getTreeHash, SettingsChangesHistory, lambda resolution, or the new setting — those strings appear only in the CI job-setup banner (the PR's changed-files metadata), before any test ran.

The sync will re-run on 7074a41 once it propagates to the sync branch; the failing jobs are flaky/infra and should clear on a rerun.

`04490_optimize_and_compare_chain_work_budget` collided with two tests
that landed on `master` after this branch's merge-base
(`04490_dict_get_keys_float_signed_zero_consistency` and
`04490_table_readonly_partition_commands`); `04491` is also taken on
`master`. Renumber to the next free prefix `04492`. Test content is
unchanged (a pure file rename).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed 01a56fec584: renumbered the test from 04490 → 04492 (pure file rename, content unchanged).

Why. 04490_optimize_and_compare_chain_work_budget started colliding with two tests that landed on master after this branch's merge-base — 04490_dict_get_keys_float_signed_zero_consistency and 04490_table_readonly_partition_commands — and 04491 is taken on master as well, so the next free prefix is 04492.

State of the rest of the PR (head before this push, 7074a4103c6):

  • AI Review: ✅ Approve — the earlier "Request changes" findings (map-building budget, SettingsChangesHistory compatibility) are resolved; no remaining blocker.
  • Cloud Performance: no_change — no regressions across 38 queries; the three flagged ClickBench deltas are downgraded to run-to-run variance (this is an analyzer-only change that fires solely on large AND-comparison chains).
  • No unresolved review threads.

The two red checks are pre-existing, master-wide flakes, not caused by this PR (which only touches query analysis):

  • Stateless tests (amd_asan_ubsan, distributed plan, parallel, 2/2) → 04204_global_in_join_max_rows_to_transfer_103333: Unexpected packet from server … (expected TablesStatusResponse, got ProfileInfo) — a connection-protocol desync, tracked by Fix flaky distributed query "Unexpected packet from server (expected TablesStatusResponse, got ProfileInfo)" #108854. The same signature hits 04204 on master directly (PR=0) on both 2026-06-29 and 2026-06-30, and dozens of other unrelated distributed tests (03360_bool_remote ×14, 04093_msan_fiber_distributed_false_positive ×7, 02835_parallel_replicas_over_distributed, …) across dozens of PRs the same days. The job's own randomized-settings diagnosis re-ran the test 24× with 0 failures ("not reproducible").
  • Stress test (arm_tsan) → Hung check failed, possible deadlock found — chronic flake tracked by Hung check failed, possible deadlock found #107941 (linked directly by the CI summary).

No master re-merge: merge-base 0cca85ea1a5 is <1 day old and both reds reproduce on master, so a re-merge would not turn them green.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The fresh CI run on 01a56fec584 (the 04490 → 04492 test renumber) has a single red, and it is a known master-wide flake, unrelated to this analyzer-only change:

  • AST fuzzer (amd_debug, targeted) → Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0), tracked by Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0) #108142 (testing/fuzz), which the CI summary auto-links. The assertion fires in UnionStep::updateOutputHeader during query-plan optimization (QueryPlanOptimizations::optimizeTreeFirstPass) — a code path this PR does not touch. The PR changes only the analyzer's optimize_and_compare_chain work budget and the resolveLambda recursion guard, neither of which alters query results or query-plan headers. Per CIDB this exact STID hit master directly (PR=0) on 2026-06-30 and ~27 other unrelated PRs the same day, and recurs daily for weeks, so it is not introduced here and a re-merge would not clear it. The job can only be re-run once the (still in-progress) run finishes.

This is a different red from the two flakes noted on the previous run (04204_global_in_join_max_rows_to_transfer_103333 desync #108854 and the arm_tsan Hung check #107941), which were superseded by the renumber push.

Otherwise the PR is ready: AI Review is ✅ Approve, there are no unresolved review threads, and it is MERGEABLE. No re-merge done — merge-base 0cca85ea1a5 is under a day old, the four analyzer files the PR actually changes have zero drift on master since then, and the only red reproduces on master itself.

@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.70% 77.60% -0.10%

Changed lines: Changed C/C++ lines covered: 69/72 (95.83%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The parent CI workflow run on `01a56fec584` has finished, so I re-ran its only failed job — `AST fuzzer (amd_debug, targeted)` — which is now in progress (run 28473939037).

That single red is the chronic master-wide AST-fuzzer flake Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0), tracked by the open issue #108142. It fires in UnionStep::updateOutputHeader during query-plan optimization (QueryPlanOptimizations::optimizeTreeFirstPass), a path this analyzer-only PR does not touch. Per CIDB this exact STID hits master directly (PR=0) on multiple recent days (2× on 2026-06-30, spread across ~28 distinct PRs that day) and recurs daily since early June, so it is not introduced here. Since the fuzzer picks a fresh seed per run, the re-run should clear it.

No re-merge: merge-base 0cca85ea1a5 is still under two days old, the four analyzer files the PR actually changes have zero drift on master, and the new setting's SettingsChangesHistory entry lands in the current 26.7 section with no conflict (MERGEABLE). Otherwise the PR is ready — AI Review is ✅ Approve and there are no unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Follow-up to the previous comment: the re-run of AST fuzzer (amd_debug, targeted) on 01a56fec584 has completed successfully, confirming the earlier Block structure mismatch failure was the chronic master-wide flake (#108142) and not caused by this analyzer-only change.

The PR is now fully green — all AST-fuzzer variants, Fast test, Style check, Mergeable Check, and CH Inc sync are SUCCESS — and GitHub reports it as MERGEABLE / CLEAN. The AI review verdict is ✅ Approve, with no unresolved review threads. Ready to merge.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good change.

@alexey-milovidov alexey-milovidov self-assigned this Jul 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into master with commit 32a325f Jul 1, 2026
343 of 344 checks passed
@alexey-milovidov
alexey-milovidov deleted the optimize-lambda-resolve-recursion-guard branch July 1, 2026 08:01
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…resolve-recursion-guard

Bound the query-analysis cost of optimize_and_compare_chain (and the lambda-resolution recursion guard)
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 16, 2026
`tryOptimizeAndCompareChain` keyed every container (comparison pairs,
constants, visited set, derived-conjunct filters, existing conjuncts) by
`QueryTreeNodePtr` and passed raw nodes through the DFS, so every lookup
re-ran `getTreeHash`. The hash of a column also hashes its source, so when
the operands are columns of a large inlined subquery (many non-materialized
CTEs) each lookup walks the whole subquery: about 30 walks per chain for 5
distinct operands. On the query from ClickHouse#131134 (CTE depth 8) the visitor
hashed 16.6M nodes for a 15K-node tree.

Compute a `QueryTreeNodePtrWithHash` once per operand per call and pass the
key through the containers and the DFS (the pattern ClickHouse#108757 used for
`resolveLambda`). The existing-conjunct sets hashed every conjunct and
every candidate; a derived conjunct is always `comparison(operand,
constant)`, so index existing conjuncts of that shape by the key of their
first argument and decide with `isEqual` inside the bucket. The derived set
is unchanged.

Nodes hashed for the ClickHouse#131134 query drop from 16.6M to 3.4M, which is below
the default `optimize_and_compare_chain_max_hash_work` budget, so at
default settings the derivation now completes instead of being reverted.
With the budget off (`compatibility` before 26.7) query analysis is 2.1x
faster.

Related: ClickHouse#131134

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants