Skip to content

Do not use the subquery query result cache in plans shipped to replicas - #130376

Merged
alexey-milovidov merged 1 commit into
masterfrom
query-result-cache-no-serialized-plans
Nov 10, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
query-result-cache-no-serialized-plans

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Related: #102192

Split out of #102192 (part 4 of 6).

StreamInQueryResultCacheStep and ReadFromQueryResultCacheStep hold node-local state (a QueryResultCacheWriter, or the cached chunks) with no serialized representation.

  • A logical plan built for parallel replicas with serialize_query_plan = 1 (createRemotePlanForParallelReplicas) is shipped to the replicas, so query_cache_for_subqueries = 1 failed the whole query with Method serialize is not implemented for StreamInQueryResultCache.
  • Plan-based parallel replicas (parallel_replicas_plan_based) serialize a fragment of the local plan, including IN subquery set plans. A fragment holding a cache step is kept local, so the cache would silently disable parallel replicas and make the remote/local decision depend on cache contents.

The Planner no longer adds the subquery cache steps in either case (checked on the local and the query-level context, so a subquery's own SETTINGS cannot bypass it). The cache is still populated and read by the plan the initiator executes itself.

Tests: 04651_query_result_cache_subquery_parallel_replicas_plan_serialization, 05366_query_result_cache_subquery_plan_based_parallel_replicas, 05394_query_result_cache_subquery_view_parallel_replicas_plan_serialization.

Changelog category (leave one):

  • Improvement

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

Queries with query_cache_for_subqueries = 1 no longer fail with Method serialize is not implemented for StreamInQueryResultCache under parallel replicas with serialize_query_plan = 1.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130376]

Version info

  • Merged into: 26.11.1.1843-master (included in 26.11 and later)

Split out of #102192.

`StreamInQueryResultCacheStep` and `ReadFromQueryResultCacheStep` hold
node-local state (a `QueryResultCacheWriter`, or the cached chunks) with no
serialized representation. A logical plan built for parallel replicas with
`serialize_query_plan = 1` (`createRemotePlanForParallelReplicas`) is shipped
to the replicas, so `query_cache_for_subqueries = 1` failed the whole query with
`Method serialize is not implemented for StreamInQueryResultCache`.

Plan-based parallel replicas serialize a fragment of the local plan, including
`IN` subquery set plans; a fragment holding a cache step is kept local, so the
cache would silently disable parallel replicas and make the remote/local
decision depend on cache contents.

The Planner no longer adds the cache steps in either case. The cache is still
populated and read by the plan the initiator executes itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). label Nov 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [747feb5]

Summary: ✅


AI Review

Summary

Reviewed #130376 at 747feb5fab5007f6f2ad411f5001d64af2c463f6. The change excludes node-local subquery cache steps from logical plans and plans eligible for plan-based parallel replicas, while preserving caching for local execution. No actionable findings. All three added regression tests passed in the Fast test report.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 747feb5fa with master 213bd8dd0 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 35e918caf; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 20 s compile time in total, 7 of them have a recent master baseline.

Job report

@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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 10, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 10, 2026
Merged via the queue into master with commit 5996d4e Nov 10, 2026
191 of 192 checks passed
@alexey-milovidov
alexey-milovidov deleted the query-result-cache-no-serialized-plans branch November 10, 2026 11:25
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 2026
devcrafter added a commit that referenced this pull request Nov 10, 2026
Add the subquery query result cache tests: the cache is not used with plan-based parallel replicas since #130376.
Add `03707_autopr_unsupported_cases` (the `LIMIT` is shipped since #129811) and `03401_..._no_sorting` (#128537).
Remove the tests that pass now: the temporary table ones (#129223), the `LIMIT` ones (#129811), and those fixed on master.

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

comp-query-analyzer Semantic analysis + logical/physical planning + rewrites (Analyzer and Planner modules). pr-improvement Pull request with some product 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