Keep parallel replicas for additional_table_filters under plan-based parallel replicas #127058

Merged
devcrafter opened 8:39pm on October 20, 2026 wanted to merge 1 ฮ” into clickhouse/clickhouse master from
pr-plan-based-additional-table-filters

Pull Request Overview

  • Opened on October 20, 2026
  • Status Merged
  • Commit count 3 with first commit October 20, 2026

Total Delta

1 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
 
6.4 days Authoring 1 commit before pull request opened for review
 
0.1 days Awaiting first review
 
1.5 days Revising work with 2 commits in response to 2 reviews that left 2 comments
 
17.0 days Merge to deploy (still awaiting deployment)

Total time for pull request 8.0 business days from first commit authored to merge
Still awaiting deployment

Author avatar

Keep parallel replicas for additional_table_filters under plan-based parallel replicas

A query with additional_table_filters silently loses parallel replicas, because a follower
re-resolves the setting's keys against its own current database and can match the wrong table. The
check that disables it exempts serialize_query_plan = 1, where the initiator lowers the filter into
a FilterStep and ships the plan. Plan-based parallel replicas ships the plan the same way -
ReadFromParallelReplicas passes QueryProcessingStage::QueryPlan and the plan itself to the remote
executor, whatever serialize_query_plan says - so the follower re-resolves nothing there either, and
the check now exempts it too.

Measured with parallel_replicas_local_plan = 0, so every row comes from a replica reading the
shipped fragment: SELECT count() over 50000 rows with additional_table_filters = {'t': 'y < 5'}
returns 25000, and ParallelReplicasQueryCount goes from 0 to 1. The new test asserts both, and fails
on master for the second one.

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

Queries using additional_table_filters no longer lose parallel replicas when
parallel_replicas_plan_based is enabled.

๐Ÿค– Generated with Claude Code


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

Version info


  • Merged into: 26.11.1.984-master (included in 26.11 and later)
    <!-- ch-version-info:end -->

Comments Threads Pending Resolution

groeneai reviewed and approved this work on October 29, 2026
groeneai left a comment

I checked this on a local debug build of fbb663f against the same tree with the `Planner.cpp` hunk reverted. Looks correct to me.

The two places that ship the query as text, [`buildQueryPlanForParallelReplicas`](https://github.com/ClickHouse/ClickHouse/blob/fbb663f373de3fe60d8aa623fbf6934d85f8449a/src/Planner/Planner.cpp#L3093-L3098) and [`executeQueryWithParallelReplicas`](https://github.com/ClickHouse/ClickHouse/blob/fbb663f373de3fe60d8aa623fbf6934d85f8449a/src/Planner/PlannerJoinTree.cpp#L2972-L2977), are gated on the same `parallel_replicas_plan_based` value the check now reads, and [`ReadFromParallelReplicasStep`](https://github.com/ClickHouse/ClickHouse/blob/fbb663f373de3fe60d8aa623fbf6934d85f8449a/src/Processors/QueryPlan/ReadFromParallelReplicas.cpp#L252) always sends the fragment as `QueryProcessingStage::QueryPlan`. So with the setting on, a query either stays local or ships a fragment, and `EXPLAIN distributed = 1` shows `Filter (additional filter)` inside it, under the partial aggregation.

Measured with `parallel_replicas_plan_based = 1, serialize_query_plan = 0` at `parallel_replicas_local_plan` 0 and 1, against `enable_parallel_replicas = 0`: 18 query shapes now use parallel replicas (`ParallelReplicasQueryCount` 0 on master, at least 1 here) and all return the same result. They cover a bare key while the follower's `default` database has a same-named table, `db.table`, alias and other-database keys, a view and its inner table, an `IN` subquery's table, both sides of an INNER join, the right side of a LEFT and a RIGHT join, `UNION ALL`, a CTE and `GROUP BY`. The new test fails without the fix for the intended reason (10/10, second line `0`) and passed 40/40 with randomized settings.

Two notes, neither blocking:
- My #118580 changes the same condition and error message. They compose: with this PR, the `parallel_replicas_plan_based` arm of #118580's condition becomes redundant, and I'll drop it there if this lands first. A subquery with `SETTINGS parallel_replicas_plan_based = 0, serialize_query_plan = 1` and `parallel_replicas_local_plan = 0` still drops the filter (50000 rows instead of 25000), here and on master alike; that is the `serialize_query_plan` exemption, which #118580 narrows.
- The first query of `04207_pr_additional_filters` expects `SUPPORT_IS_DISABLED` with `serialize_query_plan = 0` but doesn't pin `parallel_replicas_plan_based = 0`, so it stops throwing once plan-based is on by default (#112351).

Resolved Comment Threads

No resolved comments have been left on this PR.