Ignore parallel_replicas_allow_in_with_subquery under plan-based parallel replicas #127064

Open
devcrafter opened 8:47pm on October 20, 2026 wants to merge 0 ฮ” into clickhouse/clickhouse master from
pr-plan-based-in-with-subquery

Pull Request Overview

  • Opened on October 20, 2026
  • Status Open
  • Commit count 1 with first commit October 20, 2026

Total Delta

0 Total Diff Delta

Open Days

Open 26 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
0.0 days Authoring 1 commit before pull request opened for review
 
0.0 days Awaiting first review
 
25.0 days Revising work with 0 commits in response to 1 review that left 3 comments

Total time for pull request still awaiting merge (longer than repo's target): 25.0 business days

Author avatar

Ignore parallel_replicas_allow_in_with_subquery under plan-based parallel replicas

parallel_replicas_allow_in_with_subquery = 0 disables parallel replicas for a query whose prepared
sets have subqueries, because the query-based implementation has every follower execute the IN
subquery. Plan-based creates the set on the initiator in a CreatingSet branch before the main query
and ships a fragment that only refers to the finished set, so no follower executes the subquery and
the setting has nothing to protect against. The check now applies to the query-based implementation
only.

What it costs today is the set subquery's own read, not the main one.
ParallelReplicasQueryCount for a count() filtered by IN (SELECT ... FROM <MergeTree>),
with parallel_replicas_local_plan = 0:

allow_in_with_subquery = 0
= 1

parallel_replicas_plan_based = 1, before
1
2

parallel_replicas_plan_based = 1, after
2
2

parallel_replicas_plan_based = 0, before and after
1
1

The new test asserts the two counts under plan-based and the result either way; it reads 1 for the
first row on master.

Related: https://github.com/ClickHouse/ClickHouse/pull/112351

Changelog category (leave one):


  • Improvement

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

With parallel_replicas_plan_based enabled, parallel_replicas_allow_in_with_subquery = 0 no longer
switches parallel replicas off for the subquery that builds an IN set.

๐Ÿค– Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127064]
<!-- CI automatic block end :ci_links: -->

Comments Threads Pending Resolution

clickhouse-gh[bot] reviewed on October 20, 2026
src/Planner/Planner.cpp
2933
    /// `parallel_replicas_allow_in_with_subquery` guards against every follower executing the `IN`
Opus 5
2934
    /// subquery, which is how the query-based implementation runs it. Plan-based parallel replicas
Opus 5
2935
    /// creates the set on the initiator, before the main query, and the fragment the followers read
Opus 5
2936
    /// only refers to the finished set - so there is nothing for the setting to protect against.
2933 2937
    if (query_context->canUseTaskBasedParallelReplicas()
 && !settings[Setting::parallel_replicas_plan_based]
)

Resolved Comment Threads

No resolved comments have been left on this PR.