Repository navigation
Do not pre-filter a join side with a condition that reads no column - #117569
Conversation
The partial join filter push-down extracts every conjunct whose columns are
available on a side. A conjunct that reads no column at all satisfies that
check vacuously, so a provably-true, column-free predicate was pushed to both
sides. Pre-filtering with it removes nothing, but it interposes a `Filter`
step, and that changes what later optimizations recognize: a `Filter` above a
key-value right side hides the prepared storage from the direct-join
detection. With `join_algorithm = 'direct'` there is no fallback, so a working
query started failing because of a conjunct that cannot change which rows
qualify:
SELECT value2 FROM t2 LEFT JOIN rdb ON rdb.key == t2.k
SETTINGS join_algorithm = 'direct'; -- works
SELECT value2 FROM t2 LEFT JOIN rdb ON rdb.key == t2.k WHERE materialize(1)
SETTINGS join_algorithm = 'direct';
-- Code: 48. Can't execute any of specified algorithms for specified
-- strictness/kind and right storage type. (NOT_IMPLEMENTED)
`toNullable(256)` and `CAST(1 AS LowCardinality(Nullable(UInt8)))` produce the
same failure, and `query_plan_filter_push_down = 0` cures all of them.
A column-free conjunct is now only pushed when it is a constant already known
to be false: that one case is worth a `Filter`, because it makes the side's
read provably empty, which the join-order estimator relies on
(`04516_join_order_estimation_pruned_parts`).
Closes: #113969
|
Workflow [PR], commit [4cade36] Summary: ✅
AI ReviewSummaryThis PR fixes the real correctness/regression cases around column-free conjunct push-down on joins: the new Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 4cade36.
Changed lines: Changed C/C++ lines covered: 27/27 (100.00%) · Uncovered code |
|
The column-free gate fixes the loud Verified on 26.9.1.1 at default settings: with SELECT count() FROM t1 JOIN t2 ON t1.k = t2.k
WHERE (t1.a = 0 AND (t1.b + rand()) % 2 = 0) OR (t1.a = 1 AND t2.c >= 0)returns 62699 with Two suggestions: a determinism check in |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 19 s compile time in total, 8 of them have a recent master baseline. |
`indexHint` carries its condition in a separate inner expression, so in the
outer one it reads no column - exactly the shape this branch stops pushing to
the join sides. On the non-preserved side of an OUTER join the push was not a
no-op: pruning granules there turned matched rows into unmatched ones, the
preserved side then got default values for the right columns, and those
defaults passed the accompanying predicate, so the query returned a much
larger row set at default settings:
SELECT count() FROM jl AS l LEFT JOIN jr AS r ON l.id = r.id
WHERE indexHint(r.id < 150) AND (r.id < 150);
-- 958, while the same query without the hint, and the INNER JOIN, return 150
Closes: #112035
…junct-join-push-down-113969
The carve-out that kept a provably false column-free conjunct pushable
reproduced the very failure this change fixes. A `Filter` above a
key-value right side hides the prepared storage from the direct-join
detection, so with `join_algorithm = 'direct'` forced,
SELECT value2 FROM t_direct_left LEFT JOIN t_direct_right
ON t_direct_right.key == t_direct_left.k WHERE 0
failed with `NOT_IMPLEMENTED` exactly like the `materialize(1)` case,
because the folded `0` was still extracted and pushed below the join.
The carve-out also bought nothing: the copy of the filter that stays
above the join already drops every row, so the pushed copy only changes
which optimizations recognize the plan. `extractPartialPredicate` now
extracts a leaf only when it reads at least one column of the side it is
extracted for, which makes the rule total and removes the inconsistency
between a folded `0` and a `materialize(0)` that constant folding does
not see.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…analyzer `clickhouse-test` randomizes `use_join_disjunctions_push_down`, and it passes randomized settings on the client command line, where they are per-query settings that outrank a `SET` issued earlier in the session. Every query now pins the setting in its own `SETTINGS` clause, so the runs that flip it to `0` no longer make the guard pass vacuously. The old analyzer cannot resolve a qualified column of a joined table inside `indexHint` at all - it answers `UNKNOWN_IDENTIFIER` before the optimization under test runs - so the file is tagged `no-old-analyzer`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The partial predicate is pushed below the join while the original filter stays above it, so an extracted leaf is evaluated twice and a per-row draw such as `rand` becomes two independent coin flips. Master already rejects a non-deterministic subtree in `onlyDependsOnAvailableColumns`, but no test covers the reported shape, where the leaf sits inside a disjunction that spans both sides and only the `Or` branch of `extractPartialPredicate` can act on it. Related: #116930 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @zlareb1 thank you for the measurement — the class you describe is real, and it turned out to be already closed on
/// The extracted predicate runs in addition to the filter above the JOIN, so a per-row draw such as
/// `rand` happens twice and only a row passing both survives; a lambda body is a separate DAG.
if (!allNodeFunctions(node, [](const IFunctionBase & function) { return function.isDeterministicInScopeOfQuery(); }))
return false;Verified on the merged branch with your fixture shape: the plan keeps the non-deterministic leaf above the join and extracts only the deterministic part of the disjunction, and the count now agrees with the push-down-off arm. I added Agreed on your second point: #116930 should be judged on the class, not on its literal repro, and it is the determinism gate on |
Removing it regressed `04516_join_order_estimation_pruned_parts` on
`master`, whose `WHERE 0` probe asserts the pruned side is estimated as
an exact empty relation:
- │ f[0] ⋈ d[0]
+ │ f[101000] ⋈ d[10000]
So a folded always-false constant stays pushable, and the carve-out
deliberately stops there rather than deriving always-false for an
unfolded expression such as `materialize(0)`. Widening it that way was
measured to buy only symmetry with the folded case while costing the
`NOT_IMPLEMENTED` this change exists to remove:
Code: 48. None of the algorithms enabled by the 'join_algorithm'
setting [direct] can execute this ALL INNER JOIN with the given right
table storage type. (NOT_IMPLEMENTED)
(query: SELECT count() FROM (SELECT value2 FROM t_direct_left
LEFT JOIN t_direct_right ON t_direct_right.key == t_direct_left.k
WHERE materialize(0) SETTINGS join_algorithm = 'direct'))
`05101` now states which of the two directions each case belongs to.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…junct-join-push-down-113969
…bled Address review: a column-free conjunct such as a folded `WHERE 0` depends on no column, so it passed `tryToExtractPartialPredicate` even for a side that was given an empty allowed-column set because its push-down is disabled. Above a `JoinStepLogicalLookup` the inserted `Filter` hides the prepared storage from the direct-join detection, and a forced `join_algorithm = 'direct'` failed with `NOT_IMPLEMENTED` instead of returning an empty result. Skip such a side in `tryPushDownOverJoinStep`; the join-order estimator still reads the empty relation from the other side (`04516_join_order_estimation_pruned_parts`). Add folded `WHERE 0` / `WHERE toNullable(NULL)` direct-join cases to the test, and renumber the three tests to `05227`-`05229` after the merge with `master`, because their old prefixes were taken meanwhile. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed
indexHintover the non-preserved side of an OUTER join silently returning extra rows, andjoin_algorithm = 'direct'failing withNOT_IMPLEMENTEDwhen a column-free conjunct such asmaterialize(1)is added to theWHEREclause.Documentation entry for user-facing changes
The partial join filter push-down extracts every conjunct whose columns are available on a side. A conjunct that reads no column at all satisfies that check vacuously, so it was pushed to both sides. Two different things then go wrong.
Wrong results.
indexHintcarries its condition in a separate inner expression, so in the outer one it reads no column. On the non-preserved side of an OUTER join pushing it is not a no-op: pruning granules there turns matched rows into unmatched ones, the preserved side then gets default values for the right columns, and those defaults pass the accompanying predicate:A failing query. Pre-filtering with a provably-true conjunct removes nothing, but it interposes a
Filterstep, and that changes what later optimizations recognize: aFilterabove a key-value right side hides the prepared storage from the direct-join detection. Withjoin_algorithm = 'direct'there is no fallback, so a working query started failing because of a conjunct that cannot change which rows qualify:toNullable(256)andCAST(1 AS LowCardinality(Nullable(UInt8)))produce the same failure, andquery_plan_filter_push_down = 0cures all of them.A column-free conjunct is now only pushed when it is a constant the DAG has already folded to false: that one case is worth a
Filter, because it makes the side's read provably empty, which the join-order estimator turns into an exact empty relation (04516_join_order_estimation_pruned_parts). Even that constant is never offered to a side whose push-down is disabled, such as a preparedJoinStepLogicalLookupright side: the vacuous column check used to let it through with an empty allowed-column set, and the resultingFilterhid the key-value storage just like thematerialize(1)case. The estimator still reads the empty relation from the other side.The carve-out deliberately stops at the folded constant and does not derive always-false for an unfolded expression such as
materialize(0). Widening it that way was implemented and measured: it buys only symmetry with the folded case, and it costs theNOT_IMPLEMENTEDabove for one more class of queries, because the filter it lets through is exactly theFilterthat hides the key-value side.05227assertsmaterialize(0)andmaterialize(toNullable(NULL)), as well as the foldedWHERE 0andWHERE toNullable(NULL), return0under a forced direct join.Non-deterministic conjuncts that also read a column are a separate class, reported in #116930. That one is already closed on
masterby the determinism gate inonlyDependsOnAvailableColumns, which usesallNodeFunctionsand so also sees into lambda inner DAGs.05229_nondeterministic_conjunct_join_push_downadds the reported repro shape, where the non-deterministic leaf sits inside a disjunction spanning both sides and only theOrbranch ofextractPartialPredicatecan act on it.05228is taggedno-old-analyzer: the old analyzer answersUNKNOWN_IDENTIFIERfor a qualified column of a joined table insideindexHint, before the optimization under test runs. All three regression tests pinuse_join_disjunctions_push_down = 1in each query's ownSETTINGSclause, because the runner passes randomized settings on the client command line, where they are per-query settings that outrank a sessionSET.Closes: #113969
Closes: #112035
Closes: #120463
Related: #116930
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/117569]
Version info
26.10.1.2099-master(included in26.10and later)