Repository navigation
Filter step decouple folded predicate - #123293
Conversation
|
Workflow [PR], commit [43e8a05] Summary: ✅
AI ReviewSummaryThis PR moves the Final Verdict
LLVM Coverage ReportMeasured on commit 43e8a05.
Changed lines: Changed C/C++ lines covered: 51/54 (94.44%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
…structor only The fold of a filter predicate that is constant through `materialize` (#78166) replaced the filter output by the constant, so it was safe only while the filter column was removed. A `FilterStep` with a kept column was folded later, by the pruning of unused columns, once the column became removable: the pruning analysis worked on a folded clone of the DAG, carried `fold_filter_predicate` to the application, and the same happened for PREWHERE in `ReadFromMergeTree`. Now the constructor folds a kept filter column as well: the column stays an output as it was, the constant becomes a new output under a new name, and the filter reads and removes the constant. The output header does not change, and once nobody reads the kept column, removing unused columns drops it like any other. So the pruning does not fold at all any more: `fold_filter_predicate`, the folded clone and the fold in `applyToOutputs` are gone. The `materialize` that the fold is for comes from other optimizations, such as making the headers of `UNION` branches compatible, and always reaches a filter through a `FilterStep`. An explicit `PREWHERE` over `materialize`, which only the pruning of `ReadFromMergeTree` folded, is not folded any more, and `04926_fold_filter_through_materialize_prewhere` is removed with it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
b288c64 to
43e8a05
Compare
| EXPLAIN PLAN actions = 1 | ||
| SELECT count() | ||
| FROM prewhere_materialize_fold | ||
| PREWHERE materialize(1) = 0 |
There was a problem hiding this comment.
The reason the test is removed: I don't care about the case when user specified such a condition manually. The issue was with the optimizations, e.g. when predicate-push-down over UNION took materialized which was needed to fix constantness.
Related: #122952
Related: #105987
Related: #78166
A follow-up to #122952. The
FilterStepconstructor now folds a filter predicate that is constant throughmaterializealso when the filter column is kept, so the pruning of unused columns does not fold at all any more.#105987 folds such a predicate by replacing the filter output with the constant. That is safe only while the filter column is removed, so the constructor folded only in that case. A
FilterStepthat kept the column was folded later, bythe pruning of unused columns, once the column became removable. To do that, the pruning analysis worked on a folded clone of the DAG and carried a
fold_filter_predicateflag to the step that applies it.ReadFromMergeTreedid thesame for
PREWHERE.Now the constructor handles a kept filter column as well: the column stays an output as it was, the constant becomes a new output under a new name, and the filter reads and removes the constant. The output header does not change. When
nothing reads the kept column any more, the pruning removes it like any other unused column. So the folded clone,
fold_filter_predicateand the fold inapplyToOutputsare gone, and the analysis works on the DAG as it is.The
materializethat the fold is for comes from other optimizations, such as making the headers ofUNIONbranches compatible, and it always reaches a filter through aFilterStep. An explicitPREWHEREovermaterializewasfolded only by the pruning of
ReadFromMergeTree, and it is not folded any more. We do not expect that in real queries: a user who writesmaterializeinPREWHEREasks for the column to be materialized.04926_fold_filter_through_materialize_prewhereis removed with it. The new test05293_fold_filter_through_materialize_kept_filter_columncovers the fold with a kept filter column.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Later
Workflow [PR]
Sync PR [sync-upstream/pr/123293]
Version info
26.10.1.1932-master(included in26.10and later)