Repository navigation
Conversation
`tryBuildPrewhereSteps` groups adjacent PREWHERE conjuncts that read the same columns into one read step. A user predicate on a join key (`less(b, 8192)`) and the join runtime filter `__applyFilter` on that same key were therefore fused into one step. Since ClickHouse#131075 a step carrying any synthesized dynamic filter is marked `is_query_prewhere = false`, which excludes the whole step from the PREWHERE-effectiveness events (`GranulesReadByPrewhereReaders`, `GranulesSkippedByPrewhereReaders`, `RowsSkippedByPrewhereReaders`). The fused step then reported `0 0 0` even though the user predicate dropped 96% of the granules. Replace the `__topKFilter`-specific `follows_top_k_filter` split rule with a symmetric one: a synthesized dynamic filter and a user predicate never share a step, regardless of `read_ahead_columns`. Each is attributed on its own; the shared column is still read once through `group_read_step`. This also covers a build-side-key predicate the planner pushes into the probe scan (`WHERE d.x < 8192`) and a user conjunct on the `ORDER BY` column when the caller passes `read_ahead_columns = false`, both of which the old top-K rule missed. Covered by a new case in `05572_prewhere_events_exclude_dynamic_filters`. Closes: ClickHouse#131263
|
Workflow [PR], commit [bce5746] Summary: ✅
AI ReviewSummarySeparates synthesized dynamic filters from user predicates in Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
leshikus
left a comment
There was a problem hiding this comment.
This PR puts the optimizer's filters (__topKFilter, __applyFilter) in a separate PREWHERE read step from the user's conditions on the same column, so the PREWHERE counters count only the user's conditions. Looks good.
…rewhere-attribution Conflict in MergeTreeSplitPrewhereIntoReadSteps.cpp with ClickHouse#131511: keep its `crosses_dynamic_filter_boundary` split rule, drop only `is_first_unattributed` added by ClickHouse#122380. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port the unconditional dynamic-filter boundary into `appendGroups`, preserving alias splitting, query-cache attribution, exception guards, and shared column reads. Related: ClickHouse#129445 Related: ClickHouse#131511
Closes: #131263
Related: #131075
The PREWHERE-effectiveness
ProfileEvents(GranulesReadByPrewhereReaders,GranulesSkippedByPrewhereReaders,RowsSkippedByPrewhereReaders) count a readstep only when it is entirely a user query predicate; a step carrying a
synthesized dynamic filter (the
__topKFilterofORDER BY ... LIMIT, a joinruntime filter
__applyFilter) is markedis_query_prewhere = falseandexcluded (#131075).
But
tryBuildPrewhereStepsgroups adjacent conjuncts that read the same columnsinto one step. A user predicate on a join key (
less(b, 8192)) and the runtimefilter
__applyFilteron that same key were fused into one step, so the wholestep — user predicate included — was excluded, and the events reported
0 0 0even though PREWHERE dropped 96% of the granules. Only
__topKFilterescapedthis, because
follows_top_k_filteralready split it off (and only whenread_ahead_columnswas set).This replaces the
__topKFilter-specific split rule with a symmetric one: asynthesized dynamic filter and a user predicate never share a step, regardless
of
read_ahead_columns. Each is then attributed on its own, and the sharedcolumn is still read once through
group_read_step. The symmetric rule subsumesfollows_top_k_filterand additionally fixes two cases the old rule missed: abuild-side-key predicate the planner pushes into the probe scan
(
WHERE d.x < 8192), and a user conjunct on theORDER BYcolumn when thecaller passes
read_ahead_columns = false.Query results are unchanged — splitting only adds a step boundary; the per-step
filters are still combined with
AND. Covered by a new case in05572_prewhere_events_exclude_dynamic_filters.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/131511]
Version info
26.11.1.2316-master(included in26.11and later)