Skip to content

Propagate outer WHERE through StorageView for skip unused shards - #98754

Merged
KochetovNicolai merged 1 commit into
masterfrom
fixing-98613
Mar 5, 2026
Merged

KochetovNicolai merged 1 commit into
masterfrom
fixing-98613

Conversation

@KochetovNicolai

@KochetovNicolai KochetovNicolai commented Mar 4, 2026 •

Copy link
Copy Markdown
Member

When querying a Distributed table through a View with force_optimize_skip_unused_shards = 1, the query failed with UNABLE_TO_SKIP_UNUSED_SHARDS because the outer WHERE clause was never propagated to the inner distributed table during filter analysis.

Fix: recognize StorageView in collectFiltersForAnalysis, and accept an optional post-filter parameter that flows from StorageView::read through InterpreterSelectQueryAnalyzer and Planner into filter analysis, where it is injected as a FilterStep on top of the dummy plan. Predicate pushdown then pushes it to the ReadFromDummy for the distributed table, making the filter available for shard skipping.

Closes #98613

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

Fix optimize_skip_unused_shards optimization with the analyzer in case Distributed storage is used in a View.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.3.1.429
  • Backported to: 26.2.5.38, 26.1.8.9

@CLAassistant

CLAassistant commented Mar 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh

clickhouse-gh Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [19a4e3d]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) failure
Changed settings are not reflected in the settings changes history (see changed_settings.txt) FAIL cidb IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 4, 2026
When querying a `Distributed` table through a `View` with
`force_optimize_skip_unused_shards = 1`, the query failed with
`UNABLE_TO_SKIP_UNUSED_SHARDS` because the outer WHERE clause was never
propagated to the inner distributed table during filter analysis.

Fix: recognize `StorageView` in `collectFiltersForAnalysis`, and accept
an optional post-filter parameter that flows from `StorageView::read`
through `InterpreterSelectQueryAnalyzer` and `Planner` into filter
analysis, where it is injected as a `FilterStep` on top of the dummy
plan. Predicate pushdown then pushes it to the `ReadFromDummy` for the
distributed table, making the filter available for shard skipping.

Closes #98613

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@KochetovNicolai
KochetovNicolai marked this pull request as ready for review March 4, 2026 16:40
@KochetovNicolai
KochetovNicolai added this pull request to the merge queue Mar 5, 2026
Merged via the queue into master with commit 00514ac Mar 5, 2026
287 of 290 checks passed
@KochetovNicolai
KochetovNicolai deleted the fixing-98613 branch March 5, 2026 13:31
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 5, 2026
@KochetovNicolai KochetovNicolai added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Mar 18, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 18, 2026
robot-clickhouse added a commit that referenced this pull request Mar 18, 2026
robot-clickhouse added a commit that referenced this pull request Mar 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Mar 18, 2026
Backport #98754 to 26.2: Propagate outer WHERE through `StorageView` for skip unused shards
@clickhouse-gh clickhouse-gh Bot added the ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted) label Mar 27, 2026
@maxknv maxknv removed the ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted) label Mar 27, 2026
@clickhouse-gh clickhouse-gh Bot added the ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted) label Mar 27, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 28, 2026
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Mar 30, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @KochetovNicolai @novikd — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

nikitamikhaylov added a commit that referenced this pull request Mar 31, 2026
Backport #98754 to 26.1: Propagate outer WHERE through `StorageView` for skip unused shards
@devcrafter

Copy link
Copy Markdown
Member

Hi @KochetovNicolai @novikd — while reviewing this PR I found the following:

* **Coverage gap:** No test coverage for skip_unused_shards through nested views, UNION ALL views, views with column renames, or views with aggregation — [Add test: No test coverage for skip_unused_shards through nested views #101284](https://github.com/ClickHouse/ClickHouse/pull/101284)

Could you review the test PR and add the can be tested label if it looks good? Happy to discuss — close anything that's wrong or already addressed.

@clickgapai where is reference to coverage gap report?

@clickgapai

Copy link
Copy Markdown
Contributor

@devcrafter — fair question. Here's the evidence:

Current test coverage: PR includes one test for the basic case: CREATE VIEW v AS SELECT * FROM distributed.

Untested paths in the diff:

  1. Nested views - Recursive post_filter propagation through multiple StorageView layers
  2. UNION views - Filter injection into UnionNode branches (Planner.cpp:263-268)
  3. Column renames - The all_inputs_present guard (Planner.cpp:291-304) when view renames columns
  4. Aggregation - Filter pushdown through GROUP BY to distributed tables

I verified all four scenarios work correctly on master with force_optimize_skip_unused_shards = 1 using two-shard clusters.

@clickgapai

clickgapai commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

This automated ClickGap comment is withdrawn — it surfaced internal tooling detail or was posted incompletely, and isn't actionable as written. Please disregard. (ClickGap's output guard now prevents this.)

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 ready-for-backport PR is eligible for backporting (merged 7+ days ago, not reverted)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analyzer does not skip shards through VIEWs

8 participants