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
Diff Delta:
0
About 5 Diff Delta/hour
Classified as:  General

devcrafter's Description of Work

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: -->

3 total changed files
(2 files ignored)
Loading changes...
Review complete ๐Ÿ’ช
Consider your review checksum validated.