Skip to content

Do not substitute a join key into a predicate that can throw on the other side's rows - #120069

Open
groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:fix-119883-join-equi-key-partial-predicate-pushdown
Open

groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:fix-119883-join-equi-key-partial-predicate-pushdown

Conversation

@groeneai

@groeneai groeneai commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #119883
Related: #117973

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed an exception from a JOIN query whose filter over an equi-join key uses a function that is not defined for every value, such as LIKE or toUInt64. The filter was copied to the opposite side of the join with the key column substituted, so it ran on values only that side holds, and a value the function cannot process (for LIKE, a row holding a single backslash) turned a query with a well-defined answer into an error.

Description

ActionsDAG::splitActionsForJOINFilterPushDown classifies a WHERE conjunct as pushable to both join
inputs when all of its inputs are equi-join-key columns, then copies it below the opposite side's read with
that key column substituted, so the copy runs on values the conjunct's own table never held. Deterministic
is all getConjunctionNodes tests, and a partial function is deterministic, so t2.c0 LIKE t2.c0 became
like(__table3.c0, __table3.c0) and a non-joining t3 row holding one backslash raised
CANNOT_PARSE_ESCAPE_SEQUENCE. Reproduced on 26.3, 26.6, 26.7 and 26.8. The property is partiality, not
LIKE: toUInt64(t2.c0) = 1 over a String equi-key fails the same way.

ActionsDAG::conjunctIsTotal answers one question about the conjunct: does every function in it have a
value for every value of its argument types? Six names read a discriminator, a null map or a boolean
rather than the value; comparisons and set lookups are admitted on their type pair (comparisonCanThrow,
and the set's declared key type being the probe column's own); everything else is refused, as is any
Variant, Dynamic or JSON argument, whose real function is resolved per stored alternative at execution
time. propagatePredicateAcrossEquiJoin carries the same substitution and had the same hole for a partial
IN, so it now asks that same one question.

Rejecting a conjunct loses nothing on its own side, which is classified independently; what loses the
opposite-side copy is a shape like k LIKE 'a%' or k % 2 = 0. Each test case pins one branch of the
gate: six of them throw or change the filter leg count on master, two are controls that a total conjunct
is still copied to both legs.


Workflow [PR]
Sync PR [sync-upstream/pr/120069]

groeneai and others added 4 commits September 14, 2026 08:59
…ther side's rows

`ActionsDAG::splitActionsForJOINFilterPushDown` classifies a `WHERE` conjunct as pushable to
both join inputs when every one of its inputs is an equi-join-key column, copies it to the
opposite side with that key column substituted for the equivalent one, and installs the copy
as a `FilterStep` below the opposite side's read. The copy therefore runs on values the side
the conjunct names never held.

The only property `getConjunctionNodes` tests about the conjunct's functions is
`isDeterministicInScopeOfQuery()`, and a partial function can be perfectly deterministic. So
`t2.c0 LIKE t2.c0`, which names only `t2`, became `like(__table3.c0, __table3.c0)` on the `t3`
leg, and a `t3` row holding a single backslash (an intentionally invalid LIKE pattern that is
not a join partner of anything in `t2`) turned a query with a well-defined answer into
`CANNOT_PARSE_ESCAPE_SEQUENCE`. Reported in ClickHouse#119883.

Admit a both-streams classification only for a conjunct built from functions that are total on
their argument types. The invariant is not new: the sibling pass
`propagatePredicateAcrossEquiJoin.cpp` already refuses the same transfer for the same reason in
`atomSafelySubstitutable`, gating its comparison arm on `comparisonCanThrow`, and its in-tree
comment states the argument outright. This extends that invariant from a single atom to a
conjunct, on the other carrier of the same transfer, and reuses the same free function for
comparisons.

The property that matters is partiality, not `LIKE`: `toUInt64(u2.c0) = 1` over a `String`
equi-key fails the same way for a target-only `'x'`, and is fixed by the same guard because the
walk rejects the whole conjunct on its nested `toUInt64`.

Two gates, no exemption. The type gate rejects a conjunct with a `Variant`, `Dynamic` or JSON
type anywhere in a node's type, including nested, because the default implementation then builds
the real function per stored alternative at execution time: `NOT k` over a `Dynamic` equi-key
throws `ILLEGAL_TYPE_OF_ARGUMENT` for a `String` alternative only the opposite side holds.
`hasDynamicStructure()` is not that predicate, since a plain `Variant(String, UInt64)` reports
`false`. The name gate is a closed whitelist, each member total given the type gate: the logical
functions read the boolean value and null map only, `isNull`/`isNotNull` return `UInt8` for every
argument type without reading the value, the six comparisons are admitted only when
`comparisonCanThrow` is false, and `__applyFilter` probes a set built from the very common type
its key argument is cast to, so its per-row lookup is an identity cast. `in` is not admitted
even though the sibling pass admits it: an `IN` set's key types come from the user's own
expression list and are independent of the left argument's type, so there the cast is real.

Rejecting from the both-streams classification loses nothing on the conjunct's own side, which
is classified independently into that side's list and still erased from the post-join filter.

Co-Authored-By: Claude Opus 5 <[email protected]>
The preceding commit rejected every set-probing conjunct from the both-streams
classification, `in` included. That was too coarse and it had a measured price: TPC-H Q18's
`o_orderkey IN (SELECT l_orderkey ... HAVING sum(l_quantity) > 300)` lost the copy of its
filter on the `lineitem` leg, changing the pinned plans in
`05024_tpch_join_order_plans_aggregation_pushdown` and `03836_tpch_join_order_plans`.

A set lookup casts the probe column into the set's key type once per row
(`Set::execute`), so it is total exactly when that type is already the probe column's own:
`castColumn` returns its argument untouched for equal types, and an identity cast neither
parses nor narrows a value. That is the same argument by which the preceding commit admits
the JOIN runtime filter, which reaches the same lookup with its probe cast to the very
common type its set was built from. The difference is only in how the equality is
established: the runtime filter gets it by construction, while an `IN` set's key types come
from the user's own expression list, so here it is checked on the node.

The probe type this check reads is the type the lookup receives, because a substitution's
replacement column always carries the type the name it replaces has in the JOIN output
(`filterPushDown.cpp:526-528`, `:714-715`, `:765-780`). That is what the preceding commit's
`__applyFilter` arm rests on too.

The check reads the set's declared key types, which never builds the set and therefore
cannot execute an `IN` subquery during optimization. A set whose header the planner has not
installed reports no types at all; that is treated as unknown and rejects, so the guard
fails closed. A multi-key (tuple) set and a `Variant`/`Dynamic`/JSON key type also reject.
The declared key types have `LowCardinality` removed recursively while the type the lookup
casts into keeps a nested one, so the probe type is normalized the same way; what can then
still differ between the type compared here and the cast target is a `LowCardinality`
wrapper, which re-encodes a value against a dictionary without reading it. `Nullable` is
not stripped from either side, so a `Nullable` probe never matches a bare key type.

Only the name `in` is admitted, since the per-row cast is an identity only where the types
are already equal; `notIn`, `nullIn` and `globalIn` reach the same lookup but stay rejected
because nothing here exercises them, the same rule that keeps `tuple` off the whitelist.

Co-Authored-By: Claude Opus 5 <[email protected]>
…lity guard

Eleven cases, one per decision the guard makes. The three that assert a plan shape count the
legs a conjunct's filter appears under, because `EXPLAIN actions = 1` prints
`Filter column: <expr>` and never the substituted qualified name: two legs means the conjunct
was copied to the opposite side, one means only its own side kept it.

Cases 1, 2, 2b, 5, 6b and 9 throw before this change (`Code: 25` for a trailing backslash LIKE
pattern, `Code: 6` for a string that is not a number, `Code: 43` for a `Dynamic` alternative the
function cannot accept, `Code: 27` for a string that is not a tuple) and return the joining row
after it. Cases 4 and 8 are controls that pass before and after: a total predicate and an
equal-type `IN` set are still copied to both legs, so an always-reject guard fails them. Case 3
is the negative plan assertion for the reported query, case 6 is the one for a set whose key type
differs from the probe column's, and case 7 the one for a comparison of two decimals of different
scales, which rescales one side per row.

`transform_null_in` appears in case 6b only, where it renames the function to `nullIn`: that is
the shape in which a set lookup's per-row cast is reached and throws, and it is refused by name
rather than by the type check case 6 exercises.

Co-Authored-By: Claude Opus 5 <[email protected]>
`propagatePredicateAcrossEquiJoin` is the second carrier of the substitution this
branch already guards in the both-streams filter push-down: it copies a conjunct
that sits below the join onto the other side with the equi-key substituted, and
`atomSafelySubstitutable` gated only the comparison shape, not `in`. So the same
partial set lookup was still transferred, and the copy ran on target rows the
source never held.

    CREATE TABLE pk_tup_src (c0 String) ENGINE = MergeTree ORDER BY c0;
    CREATE TABLE pk_tup_dst (c0 String) ENGINE = MergeTree ORDER BY c0;
    INSERT INTO pk_tup_src VALUES ('(1)');
    INSERT INTO pk_tup_dst VALUES ('(1)'), ('abc');

    SELECT s.c0 FROM (SELECT pk_tup_src.c0 AS c0 FROM pk_tup_src
        INNER JOIN pk_tup_dst ON pk_tup_src.c0 = pk_tup_dst.c0) AS s
    WHERE s.c0 IN (SELECT tuple(toUInt64(1)));

returned `(1)` with `query_plan_propagate_predicate_across_join = 0` and threw
`Code: 27 ... Cannot parse input: expected '(' before: 'abc'` with `= 1`, naming
`__table3.c0`, the target's column. Reachability is ordinary: the pass needs a
`FilterStep` below the join on the source side, which the push-down produces for
the conjunct's own side, and a target reading a MergeTree primary key that holds
the substituted column.

The earlier probe of this pass could not have shown it: it pinned
`transform_null_in = 1`, which renames the function to `nullIn`, a name
`atomSafelySubstitutable` refuses outright. The admitted shape is a plain `in`
whose set key type is a `Tuple`, delivered by a subquery. A constant set of that
type does not reach the throwing arm at all.

To avoid two copies of the predicate, `probeTypeMatchesSetKey` becomes the
documented `ActionsDAG::setLookupCanThrow` static with inverted polarity, so both
call sites read like the `comparisonCanThrow` line they sit next to. No type gate
is owed at the new call site: `setLookupCanThrow` already rejects a set key type
that adapts per row, and an admitted pair must have the probe type equal to that
key type, so a `Variant`/`Dynamic`/JSON probe cannot be admitted either.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 blocker over two rounds, 0 findings on
the final delta re-review) plus my own cold review of the resulting code in both rounds. Below are the
findings that changed the PR and the ones I overrode; pure internal hygiene nits are omitted.

# Sev Finding Verdict Evidence / action
1 ❌ The sibling pass propagatePredicateAcrossEquiJoin copies an IN atom whose per-row set-key cast can throw, so the shape fixed here returns through the other carrier on MergeTree tables (atomSafelySubstitutable gated only its comparison arm) AGREE, fixed @ b4ea37d Raised independently by the gate and by my own review. Witnessed on a binary that is the final tree minus exactly the guard: propagation off returns the joining row, propagation on throws Code: 27 naming the target's column. The earlier probe of that pass pinned transform_null_in = 1, which renames the function to nullIn and is refused there by name, so it could not exercise the arm. Both call sites now share one predicate
2 ⚠️ The narrowing costs the opposite-side copy for every non-whitelisted function over an equi-key AGREE, stated Named in the description with the shapes, plus the measurement that no test in the join or filter-push-down corpus exercises one and both pinned TPC-H plan tests are unchanged
3 ⚠️ The obvious question, why a closed whitelist instead of the in-tree IFunction::canThrow virtual, was answered nowhere in the PR AGREE, answered IFunctionBase, which is what a DAG node holds, declares no canThrow at all, and the IFunction default falls back to isSuitableForShortCircuitArgumentsExecution, which the header itself documents as unsafe in exactly this direction. Now one clause of the description
4 💡 The __applyFilter arm's comment names joinRuntimeFilter's type normalization as its guarantor, where the guarantee looked local to the lookup DISAGREE My finding was wrong, and the measured rebuttal is right: ExactSetRuntimeFilter::find has three arms, and the Many arm calls exact_values->execute(...) on a Set, entering the same per-row castColumnAccurate this PR's IN gate exists for, rather than hashing bytes. The lines I cited for hashing belong to ApproximateSetRuntimeFilter. The cast is an identity only because joinRuntimeFilter casts the key to the filter's element type outside the lookup, so the comment as written is the accurate one
5 💡 The EXPLAIN-count assertions do not pin every randomized plan setting DISAGREE They fail closed: a restructured plan makes the counted string vanish, so the count becomes 0 and the case fails rather than passing vacuously. 50 randomized runs of the file pass after the two new cases were added
6 💡 The first commit's message states that in is not admitted, which the second commit reverses DISAGREE The second commit names the reversal and the measured price that forced it (TPC-H Q18 losing the copy of its filter on the lineitem leg, changing two pinned plan tests), which is what a bisecting reader needs

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per
finding.

One question for the owner of this code, which I deliberately did not decide myself. The same partiality
survives for a predicate pushed below the join on its OWN table, where no substitution happens but the
predicate still runs before the join, on rows with no join partner that the post-join filter would never
have reached. With the data inverted so that the source table holds the invalid pattern, that throws both
before and after this change. Narrowing it too would change filter push-down for every join, which is
wider than a bug fix, so I left it alone and filed nothing for it. Is pre-join evaluation of a partial
predicate on its own table considered acceptable, or should it be narrowed the same way?

Session id: cron:clickhouse-review-slot-8:20260914-184000

@clickhouse-gh clickhouse-gh Bot closed this Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3bc23f6]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
05217_join_cross_type_equi_key_pushdown_use_nulls FAIL cidb
04117_join_equi_key_filter_pushdown_right_full FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100% on demand, not a rate, for each carrier. Carrier 1: t2 = {'a'}, t3 = {'a', '\'}, then SELECT c0 FROM (SELECT t2.c0 AS c0, (t2.c0 LIKE t2.c0) AS ref FROM t2 INNER JOIN t3 ON (t2.c0 = t3.c0)) AS s WHERE ref gives Code: 25 ... like(__table3.c0, __table3.c0); reproduced on the official 26.3.33.10, 26.6.5.73, 26.7.6.57 and 26.8.2.7 builds as well as on master. Carrier 2: the same two rows in MergeTree ORDER BY c0 tables with WHERE s.c0 IN (SELECT tuple(toUInt64(1))) above the join gives Code: 27 ... in(__table3.c0, ...) with query_plan_propagate_predicate_across_join = 1 and returns the joining row with = 0.
b Root cause explained? Yes, and it is one root cause with two carriers. splitActionsForJOINFilterPushDown classifies a conjunct as pushable to both inputs when all of its inputs are equi-keys, replace_equivalent_columns_in_filter rebinds the key column, and the copy becomes a FilterStep below the opposite side's read, so it runs on values that side alone holds; getConjunctionNodes only tests isDeterministicInScopeOfQuery(), and a partial function can be deterministic. propagatePredicateAcrossEquiJoin's atomSafelySubstitutable performs the same substitution and gated only its comparison shape, so a set lookup whose per-row cast into the set's key type can throw was transferred onto a MergeTree primary-key target. Inside JOIN ON the predicate stays a one-sided join filter, which is why form (a) in the issue returns the row.
c Fix matches root cause? Yes: each classification that creates the substituted copy is narrowed, at that classification. No guard at the throw site, no widened bound, no test-setting tag, LIKE is not special-cased, and the two carriers share one predicate instead of two copies of it.
d Test intent preserved / new tests added? New test 05212_join_equi_key_pushdown_partial_predicate, thirteen cases, one per decision the guards make: for each carrier a case that the unsafe transfer is refused and a control that the optimization still happens when the atom is total. No existing test's intent is weakened and no existing .reference file is edited, including the two pinned TPC-H plan tests.
e Both directions demonstrated? Yes, per case, on binaries differing by exactly the change: Code: 25 / Code: 6 / Code: 43 / Code: 27 or a leg count of 2 before; the joining row or a leg count of 1 after. Five mutation arms, each measured to bite: always-reject fails both push-down controls; comparisonCanThrow forced to true fails the comparison case; admitting every IN fails the mismatched-type case and reintroduces Code: 27; admitting no IN fails the equal-type control, the propagate-pass control and both TPC-H plan tests; reverting only the propagate-pass guard reproduces Code: 27 on that carrier's case.
f Fix is general across code paths? Yes. Both known carriers of this substitution are fixed and call one predicate: grep -rn setLookupCanThrow src/ returns the declaration, the definition and exactly two call sites. The push-down side is the single funnel for both substitution producers (equal-type equi-keys and the cross-type cast path) and for both JoinStep and JoinStepLogical; grep -rl equivalent_left_stream_column_to_right_stream_column src/ returns only ActionsDAG.{h,cpp} and filterPushDown.cpp. tryMergeFilterIntoJoinCondition was falsified as a carrier by measurement, and joinRuntimeFilter copies no user predicates.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes by construction: the guards read the real argument types, the type gate walks nested types with IDataType::forEachChild plus the type itself (so Tuple(Variant(...)) is caught), and comparisonCanThrow strips Nullable/LowCardinality itself. Measured: LowCardinality(String) keys reproduce and are fixed, Dynamic and Variant equi-keys are a test case, and a Nullable(Tuple) probe against a Tuple set key was probed on both binaries. An admitted set lookup must have its probe type equal to the set's declared key type, so a per-row-adapting probe cannot be admitted at either call site.
h Backward compatible? Yes. No setting added or re-defaulted, so SettingsChangesHistory.cpp is untouched; no format, serialization or on-disk artifact. The only observable change is a plan shape, and the copies it removes only pre-filtered rows the join drops anyway, so no result changes.
i Invariants and contracts preserved? Yes. Pure classification decisions: no allocation, no lock, no new early-return path. Rejecting from the both-streams list loses nothing on the conjunct's own side, which is classified independently and still erased from the post-join filter. The set-lookup check never calls future_set->get(), buildOrderedSetInplace() or getKeyColumns(), so it cannot execute an IN subquery during optimization, and it fails closed on any child count, node type, set header or key type it cannot establish.

Session id: cron:clickhouse-impl-slot-4:20260914-173037


/// getConjunctionNodes() classifies a conjunct as pushable to a side when all of its inputs are
/// allowed inputs of that side. A conjunct with no inputs (a pure constant such as a literal `1`
/// or a folded `NULL`) satisfies this trivially, so it is classified as pushable to EVERY side,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This closes the opposite-side substitution, but the same partial predicate is still pushed to its own side through left_stream_push_down_conjunctions / right_stream_push_down_conjunctions. Once that happens, removeUnusedConjunctions erases the original post-join filter and the pre-join FilterStep still evaluates the predicate on rows the join would have discarded.

For example, this shape can still throw on the unmatched src row holding '\\', even though the joined result is just 'a':

SELECT src.c0
FROM src INNER JOIN dst ON src.c0 = dst.c0
WHERE src.c0 LIKE src.c0;

with src = {'a', '\\'} and dst = {'a'}.

I think the same conjunctIsTotal gate needs to run for the single-side push-down lists as well, or those non-total conjuncts need to stay above the join.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verified before answering, and the mechanism is real: the own-side conjunct is pushed below the join and the post-join copy is erased, so it runs on rows with no join partner. What I measured is that this is not something this PR introduces or leaves half done.

Your exact shape (src = {'a', '\'}, dst = {'a'}, MergeTree tables), on binaries differing only by this PR's diff:

binary result
this branch, b4ea37d Code: 25 ... like(__table1.c0, __table1.c0) (CANNOT_PARSE_ESCAPE_SEQUENCE)
pristine merge base 0d04f2b same error, same text
official 26.8.2.7 same error, same text

The qualifier is __table1, i.e. src, the predicate's own table. The copy this PR removes is the one rebound to the other table, __table3 in the issue's shape, which now returns the joining row. EXPLAIN on your shape shows the scope of the change: two Filter steps below the join on the merge base (one under src, one under dst), one after this change (only the one under src).

conjunctIsTotal is also not a gate that leg can use. Put the predicate on a non-key column (ON s2.k = d2.k with WHERE s2.c0 LIKE s2.c0) and the conjunct never enters the both-streams list at all, yet it throws identically on all three binaries, while query_plan_filter_push_down = 0 removes the throw on all three. So the own-side case is not a missing gate in this classification, it is the general push-down policy: a non-total predicate is evaluated before the join for every join shape. Narrowing that would stop push-down of every partial predicate (LIKE, casts, arithmetic, JSON extraction) under every join, which is wider than a bug fix, so I left it alone and asked the owner of this code about it in the adjudication comment on this PR instead of deciding it myself.

Correct mechanism, out of scope here, no change in this PR.

@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b4ea37d42 with master 7d0926edf (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

1211 translation units recompiled, 8639 s compile time in total, 1211 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b4ea37d

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) / 05182_join_order_conflict_detector_cast_null_propagation plan-shape flip under the randomized MergeTree setting auto_statistics_types; the runner's own minimization on this lane reports 87/87 failures with the randomized settings and 0/99 without. Not caused by this PR, which does not touch that test: the same signature is on true master (17 rows) and on 29 other pull requests, all since 2026-09-14 18:54Z #120084 (external, open)
Mergeable Check rollup of the row above, no independent failure #120084 (external, open)
PR rollup of the row above, no independent failure #120084 (external, open)

Session id: cron:our-pr-ci-monitor:20260915-010059

@rschu1ze rschu1ze 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.

Looks too complex, sorry.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Agreed on the size, and most of it is mine to cut: of the 358 added lines, 224 are the test and 83 are code.

I will fold the three helpers into one predicate with an explicit function whitelist, cut the comments to what the code does not already say, and reduce the test to the two forms from the issue plus the one IN case, so roughly 30 lines of code and a 40 line test, with the same behaviour.

One thing worth weighing first: the same gate also fixes six shapes that return wrong results on master today, on equal-typed equi-keys (measured at #120290 (comment)). If you would still rather not carry this, say so and I will close the PR instead of reworking it.

Your question on the issue is answered there: #119883 (comment)

groeneai and others added 2 commits September 16, 2026 23:13
…-pushdown

Resolves the one conflict in `ActionsDAG::splitActionsForJOINFilterPushDown`: master's
cross-type representation gate (from ClickHouse#117973) and this branch's totality gate filter the same
both-streams conjunct list, so both blocks are kept, this branch's first.

Co-Authored-By: Claude Opus 5 <[email protected]>
Same behaviour, expressed as one predicate. `functionIsTotal` and `conjunctIsTotal` are folded
into `ActionsDAG::conjunctIsTotal` with the admitted names as two explicit sets, and
`setLookupCanThrow` leaves the public interface: `propagatePredicateAcrossEquiJoin` now asks the
same single question the both-streams gate asks, so the two carriers of the substitution cannot
drift apart.

The test keeps one case per scenario: the reported query, a `Dynamic` argument, a set lookup whose
key type is not the probe column's own, plus the two controls that a total conjunct is still copied
to both legs and that a matching-type set lookup is still substituted. Measured against master
3f29c3a: the three defect cases throw there (Code 25, Code 43, Code 27) and pass here, and
both controls are unchanged. Six related push-down tests produce identical output on both binaries.

Requested in review by rschu1ze: the previous shape was 358 added lines for a gate whose logic is
six admitted function names.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Simplified and pushed as 3bc23f6, master merged in the commit before it.

  • The three helpers are one predicate, ActionsDAG::conjunctIsTotal, with the admitted names as two explicit sets. setLookupCanThrow is no longer in the public interface: propagatePredicateAcrossEquiJoin asks that same one question now, so the two carriers of the substitution cannot drift apart.
  • Comments cut from 32 lines to 18 over 81 lines of code.
  • Test cut from 224 lines to 144, 15 queries to 8. Each case pins one branch of the gate: six throw or change the filter leg count on master 3f29c3a, two are controls that a total conjunct is still copied to both legs.

That is 257 added lines against 358, not the 30 plus 40 I estimated. The residue is the six admitted function names, the two type-pair oracles, and one case per branch behind them; I did not find a smaller shape that keeps k IN (...) and the join runtime filter pushed to both sides, and dropping either of those would be a silent performance regression rather than a simplification.

@groeneai

Copy link
Copy Markdown
Collaborator Author

3bc23f6 is red on Fast test, and the cause is the gate itself rather than the way I folded it into one predicate. Two pre-existing tests, neither of them in this diff, now report that a push-down they assert no longer happens. I reproduced both locally and traced which node the gate rejects:

  • 04117_join_equi_key_filter_pushdown_right_full, two cases (the conjunct arrayExists(y -> y % 1 = 0, materialize([1])) = (l.a > toDate32('1900-01-01')) and its sibling whose lambda body reads a formal bound to the key). The gate walks the conjunct and rejects arrayExists: a list of total function names cannot admit a higher-order call whose body the walk never enters.
  • 05217_join_cross_type_equi_key_pushdown_use_nulls, the two plan counts. Over a two-USING chain the first push-down substitutes the key as _CAST(id, 'UInt64'), and the second gate then sees that node and rejects _CAST. That cast is the JOIN's own key conversion, applied to every row of that side anyway.

So the gate is conservative in a way that costs behaviour that is live on master today, not only unreachable cases. My earlier sweep of six related push-down tests did not include these two, which is how it got past me.

Admitting both shapes needs two more rules on top of the 113 lines that are there: a _CAST whose target is a supertype of its source is total, and a lambda-carrying call is total when its hidden body is. I estimate 20 lines. Dropping the walk instead makes the gate about 40 lines in total and keeps both tests green, but then a throwing function one level down (toUInt64(t2.c0) = 1, case 3 in my test file) is no longer declined, so the fix would cover the reported spelling and not the class.

That is a scope decision rather than a measurement, and both directions run against your review, so I would rather have your call than guess: extend the gate, narrow it to the top-level conjunct, or close this and leave #119883 as a known limitation of the push-down. I can do any of the three.

Updating the two references is not on that list: their negative siblings assert the same 0, so pinning the new values would leave four assertions unable to fail.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Hi @rschu1ze, gentle ping on the scope call I asked for on 2026-09-17: extend the gate so that a _CAST to a supertype and a lambda-carrying call count as total (about 20 lines), narrow it to the top-level conjunct (about 40 lines total, but then toUInt64(t2.c0) = 1 is no longer declined), or close this and leave #119883 as a known limitation of the push-down. I can do any of the three; the PR is blocked only on which one you want.

@clickhouse-gh clickhouse-gh Bot added the comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... label Nov 19, 2026
@clickhouse-gh clickhouse-gh Bot removed the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Nov 19, 2026

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

INNER JOIN equality evaluates t2.c0 LIKE t2.c0 on the other table and throws on a non-joining \ row

2 participants