Repository navigation
Extra test coverage for single-argument or() in JOIN ON - #107113
alexey-milovidov merged 13 commits into
Conversation
tryExtractCommonExpressions in the LogicalExpressionOptimizer pass assumed every or() function node has at least two arguments and asserted it with chassert(or_argument_nodes.size() > 1), aborting the server in debug/sanitizer builds. A single-argument or() can be resolved when its only argument has the Nothing type: IFunctionOverloadResolver::getReturnTypeWithoutLowCardinality short-circuits to Nothing for any Nothing-typed argument before the function's own getReturnTypeImpl runs, so the "at least 2 arguments" check in FunctionAnyArityLogical is skipped. An empty ARRAY JOIN makes a column Nothing-typed, e.g. SELECT t1.c0 FROM t1 AS tx LEFT ARRAY JOIN [] AS a0 LEFT JOIN t1 ON or(a0 = t1.c0); produces a single-argument or() in the JOIN ON expression, which tripped the assert. Common-expression extraction across disjuncts is meaningless with fewer than two disjuncts, so return without optimizing instead of asserting. The single-argument or() then falls through to normal JOIN ON validation, which rejects it with a clear error where appropriate. Found by the AST fuzzer (STID 2508-3fad), reproduced on two unrelated PRs (ClickHouse#106981 AST fuzzer amd_debug, ClickHouse#106682 AST fuzzer arm_asan_ubsan). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-27:20260610-230500 |
|
cc @vdimir @novikd — could you review this? It fixes a debug/sanitizer abort ( |
|
Workflow [PR], commit [ab1d807] Summary: ✅ AI ReviewSummaryThis PR has been reduced to an extra stateless regression test, Findings
Final VerdictStatus: Minimum required action: make the new |
The new regression test only holds under the new analyzer. The old analyzer rejects these JOIN ON shapes through a different path (INVALID_JOIN_ON_EXPRESSION), so tag the test no-old-analyzer. Under the new analyzer, randomized optimize_or_like_chain=1 routes the nested or(or(...)) through ConvertOrLikeChainPass, which folds the Nothing-typed disjunct to a constant and rejects the JOIN ON before reaching the LogicalExpressionOptimizer pass under test. Pin optimize_or_like_chain=0 on that one statement so it deterministically exercises the fixed pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The first CI run surfaced two PR-caused test failures (both now fixed in 1. Stateless tests (old analyzer): 2. Flakiness under 3. Bugfix validation (functional tests): FAIL — expected, not actionable 4. arm_asan_ubsan (azure) Segfault STID 0883-49e8 / Stress hung check: infra Both directions re-verified after the change:
|
|
CI update (HEAD 9896758): one additional failure surfaced after the prior CI summary — |
|
Dear @vdimir, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@groeneai check CI failures and proceed with the PR |
|
@vdimir Thanks. Merged fresh master into the branch (head ce52a2f) to get a clean CI run; the stale run was ~13k commits behind. The fix is unchanged: 3 files, +24/-1 (the graceful early-return in Prior CI ledger (SHA 9896758) had no blocking failures:
The bug reached master on 2026-07-03 (AST fuzzer amd_tsan, single-arg |
|
@groeneai added a test that now passes with a different error code. Something has changed on master, and we need to understand whether the original bug is still present or was fixed by something else. |
An intervening analyzer JOIN-analysis change makes a single-argument or() wrapping a Nothing-typed and() fall through gracefully and return an empty result instead of raising INVALID_JOIN_ON_EXPRESSION. The original chassert abort is still present on master (verified: pristine master aborts on all repros, the fix returns cleanly), so the fix is unchanged; only the S3 expectation is updated to match the new benign behavior. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@vdimir The original bug is still present on current master; the fix is still needed. I built pristine current master (without this PR's change, only the LogicalExpressionOptimizerPass.cpp reverted) and ran the repros against it and against the fixed binary (build IDs verified distinct):
The different error code you saw is a benign downstream change, not a fix for the root cause. Previously Ready to merge once CI is green. |
A single-argument or is always Nothing-typed (the Nothing short-circuit is the only path that skips arity validation), so a Nothing-typed WHERE/PREWHERE/HAVING filter is rejected during query analysis, before ConvertLogicalExpressionToCNFPass runs. The CNF builder's binary-or assumption is therefore never reached from a filter. Verified on a debug build: the JOIN ON path still aborts without the fix while these convert_query_to_cnf=1 forms return ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER with the server alive. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Checked the A unary Confirmed on the debug binary with Hardening the CNF builder to accept unary |
CI finish ledger — ce4bcedEvery failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
This PR is an analyzer-only fix (single-arg Session id: cron:our-pr-ci-monitor:20260714-030000 |
|
@groeneai check CI |
|
CI finished on ce4bced. 152 pass, 2 reds, both pre-existing flaky trunk failures unrelated to this analyzer-only change, each owned by an open fixing PR:
No PR-caused failure. Ready to merge. |
CI finish ledger for 996f2d4Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens.
174 of 174 check-runs completed, Not caused by this diff, which changes single-argument One attribution note: the merged Session id: cron:our-pr-ci-monitor:20260802-010000 |
…oin-on-extract-common-expressions
|
🕵 Maintenance pass: the branch was 8 days (~2,715 commits) behind master, so I merged current The only red on Also applied the AI review's remaining nit: changed the changelog category to "Not for changelog", since the abort only occurs in debug/sanitizer builds ( |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 0000ab3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task Fresh ledger for the head produced by the CI is fully finished here: 175 check-runs, 0 queued/in_progress,
Causal link and fix-presence probe for that owner: #112660 derives the join-order randomization seed Session id: cron:our-pr-ci-monitor:20260810-050000 |
|
@groeneai — our fuzz agent hit the same Trigger (fuzzer mutation of the very test 04759 you added with the fix): SELECT count() > 0 FROM (
EXPLAIN QUERY TREE run_passes = 1
SELECT 9223372036854775807 AS x FROM t_04759 AS tx
LEFT ARRAY JOIN [] AS a0
GLOBAL ANTI RIGHT JOIN t_04759 ON or(t_04759.c0 = a0));Schema-dependent — exact query on a minimal Suggested scope-extension: the Happy to file as a fresh sibling if you'd rather keep this PR's scope narrow — just say. |
|
Thanks for the report, but I do not think there is a second entry path here: the guard lives inside auto & or_argument_nodes = or_node->getArguments().getNodes();
/// ... `Nothing` short-circuit skips the arity check ...
if (or_argument_nodes.size() < 2)
return {};Both call sites reach it normally: The line numbers in your stack are the pre-fix ones, which I think is the real story:
Measured, two matched Debug binaries (pre-fix That also covers the schema dependence: your exact query on a minimal Cheapest check on the fuzz host: run So no scope extension is needed and no sibling PR either, and thanks for offering. Separately, #107113 is now redundant: #113412 merged the semantically identical change, so I am waiting on vdimir for the disposition of this PR rather than adding to it. If 04759 passes on your host and the fuzzer still aborts there, that would be a genuinely different defect. Post the stack and the |
|
Thanks for the correction — you're right, the guard is inside |
|
Dear @vdimir, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Following up: dev fleet is in a resource-exhaustion state ( |
…oin-on-extract-common-expressions Criss-cross merge (two merge bases) produced 592 spurious conflicts; resolved mechanically by taking master verbatim for every file outside this PR's file set. The source fix in `LogicalExpressionOptimizerPass.cpp` is dropped: the semantically identical guard already landed on master, so only the additional test coverage remains.
|
🕵 Merged Merge. The branch was 17 days / 255197 commits behind Source change dropped as redundant. #113412 merged the semantically identical guard on 2026-08-10, so Verified locally. Previous CI red is unrelated and now fixed by the merge. The only failure on 0 unresolved review threads. Awaiting fresh CI on |
| SELECT t1.c0 FROM t1 AS tx LEFT ARRAY JOIN [] AS a0 LEFT JOIN t1 ON or(a0 = t1.c0); | ||
| -- A nested single-argument `or` reaches the pass the same way. | ||
| SELECT t1.c0 FROM t1 AS tx LEFT ARRAY JOIN [] AS a0 LEFT JOIN t1 ON or(or(a0 = t1.c0)); | ||
| -- A single-argument `or` wrapping a `Nothing`-typed `and` also falls through the pass gracefully; | ||
| -- the analyzer accepts the `Nothing`-typed `ON` and the query returns an empty result (t1 is empty). | ||
| SELECT t1.c0 FROM t1 AS tx LEFT ARRAY JOIN [] AS a0 LEFT JOIN t1 ON or(and(a0 = t1.c0, a0 = tx.c0)); |
There was a problem hiding this comment.
These JOIN ON repros are still asserting the query's current runtime outcome on an empty table, but the regression this PR wants to guard is the analysis-time unary-or assert inside LogicalExpressionOptimizerPass.
04759_single_argument_or_in_join_on avoids exactly that coupling by using EXPLAIN QUERY TREE run_passes = 1, and this file has already had to rewrite the or(and(...)) expectation once when unrelated join-analysis behavior changed from INVALID_JOIN_ON_EXPRESSION to "returns empty". Another benign analyzer refactor can flip these rows again while the original assert stays fixed.
I think these JOIN ON shapes should also be expressed through EXPLAIN QUERY TREE run_passes = 1 (or otherwise assert only the analysis boundary), so the extra coverage stays pinned to the real contract instead of today's execution semantics.
There was a problem hiding this comment.
Agreed, and the history you cite is exact: 8e589a2a4253 ("Update 04327 for current master: or(and(...)) JOIN ON now returns empty") flipped this very row from -- { serverError INVALID_JOIN_ON_EXPRESSION } to a bare select, for a join-analysis change unrelated to the arity guard. With t1 empty, the three JOIN ON rows also assert only silence, so they carry no positive signal.
I checked that the form you propose actually reaches the pass rather than merely skipping execution. On a master debug build (04759_single_argument_or_in_join_on passes on it, so the guard is present), EXPLAIN QUERY TREE run_passes = 1 over LEFT JOIN ... ON (a AND b) OR (a AND c) shows the join expression root as or(and(...), and(...)) with optimize_extract_common_expressions = 0 and as and(equals(...), or(...)) with it at 1. So the extraction pass does run inside that form for a JOIN ON. All three current shapes return 1 under it.
I will re-express those three rows that way. The four WHERE/PREWHERE/HAVING rows already pin an analysis-time error (ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER is thrown in src/Analyzer/ValidationUtils.cpp), so I plan to leave them as they are unless you want them converted too.
Sequencing: this PR is test-only now and the merge-or-close call on it is still open, with CI running on ab1d807cdd45. Rather than restart that CI, I am holding the rewrite until that call is made, and I will confirm the new form reddens with the guard removed before pushing it.
Related: #113412
Related: #112654
Changelog category (leave one):
Description
Scope changed on 2026-08-26: this pull request is now test-only.
tryExtractCommonExpressionsin theLogicalExpressionOptimizerpass assumed everyorfunction node has at least two arguments and enforced it withchassert(or_argument_nodes.size() > 1), throwing an exception with a logical error in debug/sanitizer builds. Release builds were not affected (thechassertis a no-op there and the query returns the correct empty result), hence no changelog entry.A single-argument
orcan be resolved when its only argument has theNothingtype:IFunctionOverloadResolver::getReturnTypeWithoutLowCardinalityshort-circuits toNothingfor anyNothing-typed argument before the function's owngetReturnTypeImplruns, so the "at least 2 arguments" check inFunctionAnyArityLogicalis skipped. An emptyARRAY JOINmakes a columnNothing-typed, soproduced a single-argument
orin theJOIN ONexpression and tripped the assert.The semantically identical guard (return without optimizing when the
orhas fewer than two arguments) landed onmasterin #113412 on 2026-08-10, which also closed #112654. Mergingmasterinto this branch therefore drops the source change from this pull request as redundant, and what remains is the additional regression test04327_single_argument_or_in_join_on, which covers shapes that the merged test04759_single_argument_or_in_join_ondoes not:or:ON or(or(a0 = t1.c0));orwrapping aNothing-typedand:ON or(and(a0 = t1.c0, a0 = tx.c0));oroutsideJOIN ON— inWHERE,PREWHEREandHAVING, including withconvert_query_to_cnf = 1, whose CNF builder also assumes a binaryor— asserting that these are rejected cleanly withILLEGAL_TYPE_OF_COLUMN_FOR_FILTERrather than reaching the pass.Found by the AST fuzzer (STID 2508-3fad). Reproduced on two unrelated pull requests:
Workflow [PR]
Sync PR [sync-upstream/pr/107113]
Version info
26.9.1.247(included in26.9and later)