Skip to content

Fix filter pushdown through JOINs inside VIEWs with the analyzer - #100392

Closed
alexey-milovidov wants to merge 4 commits into
masterfrom
fix-view-join-filter-pushdown
Closed

alexey-milovidov wants to merge 4 commits into
masterfrom
fix-view-join-filter-pushdown

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

When querying a VIEW that contains a JOIN over local MergeTree tables, the outer WHERE clause was not pushed down to the underlying tables.

The root cause: collectFiltersForAnalysis only runs the filter collection pipeline for specific storage types (Distributed, parallel replicas MergeTree, ObjectStorageCluster, StorageView). When a VIEW's inner query contains only plain MergeTree tables, the function returned early, discarding the post_filter (the outer WHERE clause pushed from StorageView::read).

The fix ensures the filter collection pipeline always runs when a post_filter is provided, enabling the plan optimizer to push the filter through the JOIN to individual tables.

Closes #67668

Changelog category (leave one):

  • Performance Improvement

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

Improve performance of reading from VIEWs containing JOINs. Closes #67668.

alexey-milovidov and others added 2 commits March 22, 2026 20:31
When querying a VIEW that contains a JOIN over local MergeTree tables,
the outer WHERE clause was not pushed down to the underlying tables.

The root cause: `collectFiltersForAnalysis` only runs the filter
collection pipeline for specific storage types (Distributed,
parallel replicas MergeTree, ObjectStorageCluster, StorageView). When a
VIEW's inner query contains only plain MergeTree tables, the function
returned early, discarding the `post_filter` (the outer WHERE clause
pushed from `StorageView::read`).

The fix ensures the filter collection pipeline always runs when a
`post_filter` is provided, enabling the plan optimizer to push the
filter through the JOIN to individual tables.

Closes #67668

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6b2beb3]

Summary: ✅


AI Review

Summary

This PR fixes predicate pushdown for queries over VIEW definitions containing JOIN: when an outer filter is passed as post_filter, planner filter-collection is now forced so predicates can propagate to underlying tables. The added stateless test reproduces issue #67668 and verifies partition pruning behavior. I did not find correctness, safety, concurrency, or compatibility regressions in the patch.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Mar 22, 2026
Three issues causing CI failures:

1. Background merges could merge `data_user_utm` parts (no partition key,
   both inserts land in the same partition), changing Parts: 1/2 to
   Parts: 1/1. Fix: `SYSTEM STOP MERGES` before inserting data.

2. Distributed plan CI mode sets `serialize_query_plan = 1`, which changes
   EXPLAIN output format. Fix: explicitly set `serialize_query_plan = 0`.

3. Random MergeTree settings (e.g. `add_minmax_index_for_numeric_columns`)
   could add extra index steps to the EXPLAIN output. Fix: add
   `no-random-merge-tree-settings` tag.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@KochetovNicolai KochetovNicolai self-assigned this Mar 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 24.50% 24.50% +0.00%
Branches 76.60% 76.60% +0.00%

PR changed lines: PR changed-lines coverage: 100.00% (6/6, 0 noise lines excluded)
Diff coverage report
Uncovered code

@KochetovNicolai KochetovNicolai left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does not reproduce the failure for me (on a branch without the fix).
I will take a look.

@KochetovNicolai

Copy link
Copy Markdown
Member

I've tried hard but could not reproduce the initial issue.
I suppose it could have been fixed already by #73994
#67668 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The query speed of clickhouse version 24.7.2.13 is much slower than version 23.11.3.23

2 participants