Skip to content

Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization - #104296

Merged
azat merged 13 commits into
ClickHouse:masterfrom
azat:pr-additional-filters-fix
May 20, 2026
Merged

azat merged 13 commits into
ClickHouse:masterfrom
azat:pr-additional-filters-fix

Conversation

@azat

@azat azat commented May 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization. Previously it may lead to incorrect results.

Analyzer rewrites query when sending to remotes (parallel replicas followers) to prepend database, and this breaks the additional_table_filters. And there is no clean way to fix this w/o query plan serialization (serialize_query_plan=1). So it has been explicitly disabled (throw exception) for now.

Fixes: #104219
Fixes: #102921

Version info

  • Merged into: 26.5.1.884
  • Backported to: 26.5.1.882, 26.4.4.17

@clickhouse-gh

clickhouse-gh Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b651f92]

Summary: ✅


AI Review

Summary

This PR adds an analyzer-side guard to disable or reject additional_table_filters with parallel replicas when serialize_query_plan = 0, and extends stateless coverage for strict/best-effort/serialized-plan paths. The direction is correct, but the current guard is broader than the intended execution-mode contract and introduces a new user-visible regression.

Findings

❌ Blockers

  • [src/Planner/Planner.cpp:2057] The new guard keys only on global settings (canUseParallelReplicasOnInitiator and non-empty additional_table_filters) and does not verify that the current query can actually execute with parallel replicas. This can throw SUPPORT_IS_DISABLED in strict mode for queries that cannot use parallel replicas at all (for example non-MergeTree reads, or local MergeTree with parallel_replicas_for_non_replicated_merge_tree = 0), turning a query-scoped restriction into a global setting-combination prohibition.
    Suggested fix: gate this check on actual parallel-replica usage for the current query after table-expression analysis (for example, when planner state determines a parallel-replica path is selected), while keeping current strict-vs-best-effort behavior.
Tests
  • ⚠️ Add a focused stateless test proving that with analyzer enabled and non-empty additional_table_filters, queries that do not use parallel replicas do not throw SUPPORT_IS_DISABLED when enable_parallel_replicas = 2.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
  1. Narrow the new planner guard so it triggers only when the query actually uses parallel replicas.
  2. Add regression coverage for the non-parallel query case above.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 7, 2026
@azat
azat force-pushed the pr-additional-filters-fix branch 2 times, most recently from 087f1b0 to 9c088a1 Compare May 8, 2026 08:14
@azat azat changed the title Fix applying additional_table_filters with parallel replicas and analyzer Fix trivial count optimization with additional_table_filters with parallel replicas and analyzer May 8, 2026
@azat
azat force-pushed the pr-additional-filters-fix branch from 9c088a1 to 34a064a Compare May 8, 2026 09:11
@novikd novikd self-assigned this May 8, 2026
Comment thread src/Planner/PlannerJoinTree.cpp Resolved
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label May 8, 2026
@azat
azat force-pushed the pr-additional-filters-fix branch from 5c2d3b5 to 38b242f Compare May 8, 2026 22:00
@azat

azat commented May 8, 2026 •

Copy link
Copy Markdown
Member Author

Stateless tests (amd_tsan, s3 storage, sequential, 2/2)

And this is a real problem, when local replica is slow, some follower will answer, and the answer will be wrong (since it does not apply filters)

@azat
azat force-pushed the pr-additional-filters-fix branch from 38b242f to 1658607 Compare May 18, 2026 19:55
The problem:

    Initiator: SELECT count() FROM                t additional_table_filters = {'t': 'x != 0'}
    Follower : SELECT count() FROM non_default_db.t additional_table_filters = {'t': 'x != 0'}

And now additional_table_filters cannot be matched on follower, let's
apply them if they do not have database, this will fix the problem.
@azat

azat commented May 20, 2026

Copy link
Copy Markdown
Member Author

@Algunenano I don't think we want to backport this, since the solution - disable additional_table_filters with parallel replicas for now, I will close backports

@Algunenano

Copy link
Copy Markdown
Member

@Algunenano I don't think we want to backport this, since the solution - disable additional_table_filters with parallel replicas for now, I will close backports

The problem is that we backported the initial fix, which makes the test flaky in all those branches.

@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 20, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 20, 2026
robot-clickhouse added a commit that referenced this pull request May 20, 2026
Cherry pick #104296 to 26.5: Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
robot-clickhouse added a commit that referenced this pull request May 20, 2026
…lel replicas and analyzer and w/o query plan serialization
alexey-milovidov added a commit that referenced this pull request May 21, 2026
Backport #104296 to 26.5: Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
zvonand pushed a commit to Altinity/ClickHouse that referenced this pull request May 22, 2026
…with parallel replicas and analyzer and w/o query plan serialization

(cherry picked from commit 1891234)
zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 22, 2026
Two settings used by the upstream test do not exist on 25.8
(automatic_parallel_replicas_mode, query_plan_remove_unused_columns).
Drop them and refresh the reference to capture 25.8's actual EXPLAIN
PLAN output for the serialize_query_plan=1 path, which still goes
through the trivial-count optimization on followers (count=23) — that
divergence from master is tracked separately and not covered by the
ClickHouse#104296 backport.
azat added a commit that referenced this pull request May 27, 2026
Backport #104296 to 26.4: Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
@azat

azat commented May 27, 2026

Copy link
Copy Markdown
Member Author

Indeed, but better not to backport such a change, but I've merged backports to 26.4+

@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 27, 2026
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Jul 21, 2026
Backport ClickHouse#104296 to Stable 25.8 - Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Jul 24, 2026
Backport ClickHouse#104296 to Antalya 25.8 - Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…with parallel replicas and analyzer and w/o query plan serialization
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…4296

Backport ClickHouse#104296 to 26.4: Disable additional_table_filters with parallel replicas and analyzer and w/o query plan serialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

Test 01710_projection_additional_filters is flaky

5 participants