Repository navigation
Conversation
`SELECT * APPLY (x -> arrayJoin([x, x + 1])) FROM t WHERE i > 1`, run with `ast_fuzzer_runs` and
`ast_fuzzer_oracle` set, returned a false `Code: 906 AST_FUZZER_ORACLE_MISMATCH` for a query that
answers correctly. The NoREC oracle compared `SELECT count() FROM (<the query>)` = 8 against
`SELECT countIf(i > 1) FROM t` = 2: the rewrite drops the select list, hence the lambda, hence the
row multiplication, which is exactly what its screen exists to refuse.
`ASTColumnsApplyTransformer` keeps `lambda`, `parameters` and the bare `func_name` outside
`children` - its `clone()` copies the first two by hand instead of calling `cloneChildren()` - and
`expressionContainsArrayJoinImpl` recursed over `children` only, testing a name only on an
`ASTFunction`. So a call written inside an `APPLY`, or a UDF named by `func_name` whose body contains
one, was invisible to it. One walk in the shared helper covers every caller; the name test is
factored out so the canonical-name lookup that catches `unnest` and the cycle-guarded UDF descent are
reused for the bare function name.
Measured on two binaries built from the same tree, 8 fuzzed rounds per arm, as
checks / mismatches:
* APPLY (x -> arrayJoin(...)) WHERE 16/6 -> 5/0
* APPLY (x -> unnest(...)) WHERE 12/6 -> 8/0
* APPLY (x -> aj_udf(x)) WHERE 19/4 -> 7/0
* APPLY aj_udf (bare func_name) WHERE 12/6 -> 5/0
COLUMNS('i') APPLY ... WHERE 8/4 -> 4/0
t.* APPLY ... WHERE 14/5 -> 5/0
chained APPLY ... APPLY ... WHERE 14/7 -> 4/0
* APPLY (x -> x + 1) WHERE 25/0 -> 29/0 (must stay > 0)
arrayJoin only inside a subquery WHERE 30/0 -> 20/0 (must stay > 0)
arrayJoin written in the list WHERE 0/0 -> 0/0 (already refused)
Against a real server the same query produced 4 client-visible `Code: 906` in 6 rounds before and
0 after. Reverting each of the three gate lines in turn shows the client-visible mismatch is
attributable to `isSafeForOracle` alone, and that all three gates consume the one walk.
`checkIdentityWhere` keeps running on these queries, by design: it rewrites only the `WHERE`
predicate, so both sides multiply rows identically. That is why the checks counter stays non-zero
above, and why the new test asserts the mismatch counter instead.
Two DDL surfaces change acceptance on purpose. A row policy filter and a `CHECK`/`ASSUME` constraint
carrying this spelling are now refused at statement time (`ILLEGAL_PREWHERE`, `INCORRECT_QUERY`), the
same codes the plainly written call already gets; both were accepted before and then failed on every
read or insert with `Code: 36` and `Code: 47`. Stored-metadata replay is exempt via
`isFreshTableDefinition`, so no existing table stops attaching. The two limit-pushdown callers and
the TTL and sharding-key callers are unaffected: they read the AST after the transformer has been
expanded, or the transformer is not expressible there at all.
Rejected: a local wrapper in `QueryOracleChecker.cpp` (leaves the other eight callers blind, does
not cover the `func_name` carrier, and collides with the pending non-deterministic-function screen in
that file); widening the NoREC rewrite to preserve the select list (changes what the oracle tests
rather than what it refuses, and the row-count invariant is genuinely unavailable for a
row-multiplying query); refusing every query carrying an `APPLY` transformer (the positive control
above shows the oracles run correctly on those, so it would delete real coverage and newly reject
harmless row policies and constraints).
Related: ClickHouse#118224
The walk added in the previous commit reaches three hidden members of ASTColumnsApplyTransformer, but only two of them were asserted. The lambda and a function name resolving to a SQL UDF were covered; a bare canonical function name and the parameters member were exempted as unreachable, on the strength of Code: 43 and Code: 36 measured through a SELECT. Those two codes are raised only once the expression has been resolved and evaluated, so they say nothing about the surface where this change actually alters acceptance. A row policy filter is screened straight off the parsed AST in InterpreterCreateRowPolicyQuery::execute, before name resolution, arity checking or constant folding, so neither code can fire there. Measured one policy at a time on both binaries: `* APPLY unnest` and `* APPLY (quantile(arrayJoin([0.1, 0.9])))` are each accepted at DDL by the unpatched build and then make every read of the table fail Code: 36, and both are refused at statement time with ILLEGAL_PREWHERE once the walk is in place. That is the same already-broken-at-use class as the lambda spelling, and it is the same error code this test already asserts for every other spelling. Each new branch of the walk now carries an assertion on the surface where it is reachable, so the parameters member is covered by a measurement rather than by being walked because the walk was free. Nothing is added for these two spellings to the oracle test: neither is a valid SELECT, so a fuzzer probe there could assert nothing. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 5 findings across 2 cold reviews and 2
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260924-221600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260924-213700 |
|
Workflow [PR], commit [9445450] Summary: ❌
AI ReviewSummaryThe PR fixes Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit 9445450.
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 9445450Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Nothing is PR-caused. The diff is One more in-tree half is in flight for the measurement side of this class, not linked as the owner Gates (a) to (d): 0 of 173 check runs queued or running (130 pass, 41 not selected, 2 fail), Session id: cron:our-pr-ci-monitor:20260925-040239 |
Related: #118224
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The AST fuzzer oracles now recognise an
arrayJoinwritten inside anAPPLYcolumn transformer, sothey no longer check a query whose row count they cannot predict.
Description
SELECT * APPLY (x -> arrayJoin([x, x + 1])) FROM t WHERE i > 1, run withast_fuzzer_runsandast_fuzzer_oracleset, returned a falseCode: 906 AST_FUZZER_ORACLE_MISMATCHfor a query thatanswers correctly: the NoREC oracle compared a count of 8 against a count of 2, which is exactly the
row multiplication its screen exists to refuse.
ASTColumnsApplyTransformerkeeps its lambda, its parameters and a bare function name outsidechildren, soexpressionContainsArrayJoin, which recursed overchildrenonly, never saw a callwritten inside an
APPLY. One walk in that helper covers every caller.The three oracle gates using it as their row-count screen gate 8 of the 9 oracles. The 9th rewrites
only the
WHEREpredicate, so both sides multiply rows identically and it needs no such screen.Two DDL surfaces change on purpose: a row policy filter and a
CHECK/ASSUMEconstraint carryingthis spelling are now refused at statement time (
ILLEGAL_PREWHERE,INCORRECT_QUERY), as theplainly written call already was. Both were accepted before and then failed on every read or insert
(
Code: 36,Code: 47). Stored metadata is exempt, so no existing table stops attaching, verifiedwith
DETACH/ATTACH.No CI job shows this shape and none can:
QueryFuzzerbuilds anAPPLYonly fromtoString,toTypeNameandisNull, and never recurses into a lambda it finds, so the shape has to come fromthe user's own query. The measured repro and the both-direction counters live in the new test instead.
Noticed, not addressed here: a
PROJECTIONwhose body carries the same spelling is still accepted;#117791 adds that screen and inherits this walk, in either merge order. #121897 is a different screen
in a different file, with no overlap.
Workflow [PR]
Sync PR [sync-upstream/pr/122118]