Repository navigation
Make the subquery query result cache safe under make_distributed_plan - #130377
Conversation
Split out of #102192. The Planner-level query result cache steps of a subquery hold node-local state with no serialized representation, so they must not end up in a fragment that `QueryPlan::convertToDistributed` ships to a worker. - Write path: `StreamInQueryResultCacheStep` is a removable pass-through. It no longer makes `make_distributed_plan` keep the plan local, nor stops `convertSetSourceForDistributedPlan` from distributing an `IN` set source. `cutIntoDistributedPlan` drops it before the split; the local fallback keeps it, so the cache still works there. - Read path: a cache hit replaces the whole subquery plan with a non-removable `ReadFromQueryResultCacheStep`, so the plan shape would depend on cache contents. Reads are disabled while a distributed plan is being built. The ban is keyed to a new sticky `SelectQueryOptions::building_distributed_plan` (and the query-level context), so a subquery cannot escape it with its own `SETTINGS make_distributed_plan = 0`. - Because the Planner now mutates its options, `UNION` branches and the subqueries planned for partition pruning / index analysis get their own copy. - `PlannerContext::mayBeSerializedForRemoteExecution` (which disables JIT compiled expressions) also honours `make_distributed_plan` on the sticky option and on the query-level context. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [b62668e] Summary: ✅
AI ReviewSummaryThe PR allows cacheable subqueries to participate in Final VerdictStatus: ✅ Approve |
…in Fast test With `use_index_for_in_with_subqueries = 1` the set for the `IN` subquery is built speculatively during primary key analysis by `FutureSetFromSubquery::buildOrderedSetInplace`. That build distributes only a clone of the set source, and `StreamInQueryResultCacheStep` has no `clone` yet (see #130375), so it fell back to running the original source locally and wrote the cache entry, making the "distributed" case report 1 instead of 0. The test is about the set source conversion of the deferred build, so disable the speculative build. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130377&sha=latest&name_0=PR&name_1=Fast%20test PR: #130377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…distributed-plan Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Fast test failure of |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units520 translation units recompiled, 3783 s compile time in total, 520 of them have a recent master baseline. |
# Conflicts: # src/Interpreters/SelectQueryOptions.h # src/Planner/PlannerContext.cpp
…nes the plan With `enable_cascades_optimizer = 1`, `QueryPlan::optimize` clones every step of a plan accepted by `make_distributed_plan`, and `StreamInQueryResultCacheStep` cannot be cloned, so the query threw `Cannot clone StreamInQueryResultCache plan step`. Remove the cache write steps as soon as `applyDistributedPlanFallbackToLocal` accepts the plan for distributed execution, before the optimization; the removal at the fragment cut stays as a safety net. Add a Cascades regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130377&sha=861fe54c7917a9c05e145b3960e4995213b990b7&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 ( |
|
This is the same bug as the The aborting query ( SELECT count() FROM mergeTreeAnalyzeIndexes(currentDatabase(), t_pr_ai, (key IN (SELECT (SELECT key) FROM t_pr_ai_2 ORDER BY key DESC LIMIT 10 SETTINGS enable_parallel_replicas = 1, max_parallel_replicas = 2, parallel_replicas_for_non_replicated_merge_tree = 1, cluster_for_parallel_replicas = 'test_cluster_one_shard_three_replicas_localhost'))))The fuzzed query's context has parallel replicas off, so The 2026-10-20 run is |
|
🕵 Thanks @groeneai: the stress test abort is tracked by #115916 (issue #121105), so nothing to do here. The remaining red, |
…distributed-plan Resolve conflict in `PlannerContext.h`: keep the PR's extended comment for `mayBeSerializedForRemoteExecution` and master's `[[nodiscard]]`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
…-parallel-replicas execution Under the `Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, sequential)` profile the whole query is distributed by plan-based parallel replicas, so the subquery query result cache is intentionally not probed and the test printed `0` instead of `1`. The test is about a local `UNION` branch not inheriting a sibling's `make_distributed_plan`, so disable parallel replicas like the sibling tests do. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130377&sha=8ad9b709690279f4a81bec89cce188adf8aff07e&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20sequential%29 #130377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
The style check forbids plain `std::vector` in `src`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130377&sha=61d438a7e111267b3e18e77fff15db4246aff356&name_0=PR&name_1=Style%20check #130377 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Fixed the |
Related: #102192
Split out of #102192 (part 5 of 6).
The Planner-level query result cache steps of a subquery hold node-local state with no serialized representation, so they must not end up in a fragment that
QueryPlan::convertToDistributedships to a worker undermake_distributed_plan.StreamInQueryResultCacheStepis a removable pass-through. It no longer makesmake_distributed_plankeep the plan local, nor stopsconvertSetSourceForDistributedPlanfrom distributing anINset source.cutIntoDistributedPlandrops it before the split; the local fallback keeps it, so the cache still works there.ReadFromQueryResultCacheStep, so the plan shape would depend on cache contents. Reads are disabled while a distributed plan is being built. The ban is keyed to a new stickySelectQueryOptions::building_distributed_planand to the query-level context, so a subquery cannot escape it with its ownSETTINGS make_distributed_plan = 0.UNIONbranches and the subqueries planned for partition pruning / index analysis get their own copy, so a branch-local setting does not leak into siblings.PlannerContext::mayBeSerializedForRemoteExecution(which disables JIT-compiled expressions) also honoursmake_distributed_planvia the sticky option and the query-level context.Tests:
05024_query_result_cache_subquery_distributed_plan_local_fallback,05029_make_distributed_plan_in_subquery_query_cache_set_source,05054_query_result_cache_subquery_read_ban_settings_escape,05141_query_result_cache_subquery_union_branch_isolation,05339_query_result_cache_subquery_local_fragment_no_read,05616_query_result_cache_subquery_distributed_plan_drops_write_step.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The subquery query result cache works together with
make_distributed_plan: cacheable subqueries no longer prevent distributed execution, and cache reads never change the shape of a distributed plan.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130377]
Version info
26.12.1.72-master(included in26.12and later)