You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ad32f3c
Browse filesBrowse the repository at this point in the historyBrowse files
Record the static PREWHERE conditions of a join with a runtime filter in the query condition cache
A join runtime filter is pushed into the probe side's PREWHERE together with the static `WHERE`
conditions, e.g. `and(in(c1, ...), __applyFilter(rf_c1, c1), __applyFilter(rf_c2, c2))`.
`__applyFilter` is non-deterministic on purpose, so the PREWHERE writer refuses the whole condition,
and the `WHERE` key set by `updateQueryConditionCache` is lost when the forced filter merges fuse
the runtime filter step with the `WHERE` step. Nothing records the static conjunct, so with
`enable_join_runtime_filters_index_analysis = 0` (the 26.6 default) a repeated join reads every
granule on every run: 8,639,765 rows per run instead of 311,335 on the reporter's fixture.
When the PREWHERE is such a mix, `optimizePrewhere` now finds the leading conjuncts that are,
structurally, conjuncts of the frozen `filter_actions_dag`. They are compared by a hash taken after
collapsing aliases and applying the identifier-to-column mapping `applyFilters` used, because the
PREWHERE reads `c1` through `__table1.c1` while the frozen condition reads `c1` directly. The
`PrewhereInfo` then carries the key the read side already probes for that condition and the hashes
of those conjuncts. `tryBuildPrewhereSteps` keeps them in steps of their own (it would otherwise
group `in(c1, ...)` with `__applyFilter(rf_c1, c1)`, which read the same column) and flags the last
one; a later rewrite of the PREWHERE actions fails the hash check and installs no flag. The readers
chain snapshots the granules emptied up to that step, and the select processor records them under
the key at the end of a task, only when there is something to record, since an empty write still
creates an entry. Granules emptied by the runtime filter or by any later conjunct are never
recorded, including a conjunct that join push-down adds after the key was fixed. A PREWHERE whose
conjuncts are all attributable is unchanged, and so are its key and its entry count.
Measured on the reporter's fixture (plain `MergeTree`/`AggregatingMergeTree`, 8.64M rows), median
of 5, debug build, `enable_join_runtime_filters_index_analysis = 0`: runs 2 and 3 read 311,335 rows
instead of 8,639,765, and `RuntimeFilterRowsChecked` drops from 8,639,728 to 4 because the runtime
filter now sees only rows that passed the static conjunct. With the index analysis on (the master
default) and join keys in the primary key, the runtime filter's own mark-skipping reader already
prunes to 319,527 rows and the existing guard against such readers keeps the PREWHERE writes off,
as before.
The separate JOIN plus double-PREWHERE key desync that also costs `enable_join_runtime_filters = 0`
its hits is left to its own fix.
Related: #122044
Co-Authored-By: Claude Opus 5.5 <[email protected]>
0 commit comments