Repository navigation
Do not extract a non-deterministic partial predicate below a join - #117249
Conversation
`use_join_disjunctions_push_down` pushes a per-side partial predicate below the join and keeps the original filter on top, so a non-deterministic expression is drawn twice per row, independently: a row that satisfies the query's own filter can still be discarded by the pre-filter's draw. With `WHERE (a = 1 AND rand() % 2 = 0) OR (a = 2)` the selection probability for the `a = 1` rows silently dropped from 1/2 to 1/4. Nothing else in `onlyDependsOnAvailableColumns` rejects such a function - a nullary `rand` has no inputs, so it was trivially accepted. The main filter pushdown declines for the same reason. Closes: #116930
|
Workflow [PR], commit [af2dc38] Summary: ✅
AI ReviewSummaryThis PR fixes the new analyzer / query-plan half of issue Findings
Final VerdictLLVM Coverage ReportMeasured on commit af2dc38.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes24 object files changed (+142.07 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units853 translation units recompiled, 6356 s compile time in total, 853 of them have a recent master baseline. |
|
@rschu1ze — tagging you on this one as JOIN-related, as requested. Review request sent too. |
…ns-push-down-nondeterministic
The AI review asked to reject `isStateful` functions in `onlyDependsOnAvailableColumns` as well. Such a predicate cannot reach the extraction: `tryPushDownFilter` returns early when the filter expression `hasStatefulFunctions`, so the partial-predicate path is never entered for it, and the classic order-dependent stateful functions (`rowNumberInAllBlocks`, `blockNumber`, `runningDifference`, `runningAccumulate`, `neighbor`, `generateSerialID`) additionally report `isDeterministicInScopeOfQuery() == false` and are already rejected by this change. Adding the check would therefore be unreachable code. Instead, note the upstream guard in the comment and pin the behavior with a test: the plan for a filter holding a deterministic stateful function (`timeSeriesTagsToGroup`) mentions it exactly once, so the predicate is not cloned below the join.
|
🕵 @groeneai, investigate the failure: Integration tests (amd_asan_ubsan, db disk, old analyzer, 2/6, 5/6, 6/6) and provide a fix in a separate PR. If the fix is already in progress, link it here. All three shards report a job-level |
|
Confirmed, and your reading is right: this is the CI container-memory guard, not anything this pull request touches. On all three shards the guard The arm, read from the jobs and not from the clock: all three printed Owners, split by the kernel record's victim rather than by shard (all
Live rates since 2026-09-02T00:00Z, trees carrying the guard row over trees: No old-analyzer shard has been scheduled on |
…inistic in scope of query A WASM UDF declared without `DETERMINISTIC` only overrode `isDeterministic`, so it inherited `IFunction::isDeterministicInScopeOfQuery() == true`. Query plan optimizations that only consult the query-scope answer - including the join disjunctions push-down guard added by this pull request - could therefore duplicate such a call and evaluate it independently above and below a join. `Executable` UDFs already answer `false` here.
…ns-push-down-nondeterministic
Master took 05069 for `05069_wasm_abi_buffered_constant_argument_cut`, so the test moves to 05144. The old test only compared result counts with `use_join_disjunctions_push_down` on and off, so it would have kept passing if `tryToExtractPartialPredicate` had stopped extracting anything at all. It now asserts the plan: with a disjunction whose branches touch both sides of the join, enabling the setting adds one pre-filter per side below the join and disabling it leaves only the filter above the join. Adding a `rand` conjunct keeps both pre-filters but leaves `rand` out of them, and a stateful conjunct suppresses extraction entirely. The stateful check no longer counts occurrences of the function name in a plain `EXPLAIN` - that count was 2 rather than 1 under parallel replicas, which is what made the test red in the `ParallelReplicas` stateless run, and 0 with `explain_query_plan_default = legacy`. `05145_join_disjunctions_push_down_wasm_udf` covers the WASM UDF case: a UDF declared without `DETERMINISTIC` is left in the filter above the join, while a `DETERMINISTIC` one is extracted into the pre-filter below it.
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117249&sha=6a6c9aad282ec8499f6024114a9d19463ea715bf&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is a SELECT count() IGNORE NULLS FROM t_null_const_set_index__fuzz_0 STREAM BOUNDED CURSOR {'all': {'block_number': 2}}
WHERE xor(v IS DISTINCT FROM 1023, (nullIf(65535, 7) AND firstNonDefault(65537) AND (v = 9223372036854775806)))The suspicious ingredients are |
|
The fix is already in progress: #117188, still open and with no review yet. It is the same defect you asked me about on #112968, where I linked it on 2026-08-30: #112968 (comment)
Only a bare Measured on master
Two measurements clear the ingredients you suspected. Without Worth flagging because it changes the urgency: this is no longer pull-request-only. Over 30 days that job has 66 job-level errors across 64 distinct pull requests against 2700 successes, and two are true master runs, both within the last 48 hours ( So nothing separate is owed here. #117188 is one guard line plus its regression test. |
…ns-push-down-nondeterministic # Conflicts: # src/Processors/QueryPlan/Optimizations/partialJoinFilterPushDown.cpp
`05145_join_disjunctions_push_down_wasm_udf` failed in every sequential and flaky check job: the `deterministic plan` block printed the same three lines in a different order, with the extracted pre-filter below the join coming after the `PREWHERE` step instead of before it. The order in which a plan prints the filter above the join, the per-side pre-filters below it and the `PREWHERE` steps depends on which side the join is read from, and the settings randomizer is free to flip that. The assertion is about which filter lines exist, not about their order, so sort them with `ORDER BY 1`. The same is applied to `05144_join_disjunctions_push_down_nondeterministic`, whose blocks have the same shape. The references are unchanged: the lines were already in sorted order. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Merged The determinism check this pull request added to What is still only here is the other half of the same defect, which that check does not cover: I also fixed the real red on the previous run. The stress-test @groeneai, investigate the remaining two failures and provide a fix in a separate pull request; if a fix is already in progress, link it here. Both are in Stateless tests (arm_asan_ubsan, azure, sequential) and both are about distributed-plan task scheduling, which this pull request does not touch:
I could not find an open issue for either. |
|
No separate pull request is owed: both are fixed by #118390, merged 2026-09-09 05:40:05Z as The report you linked ran without that fix. The two are one bug. 04648 runs about 8.5 minutes before 04340 in the same sequential job, and pre-fix it aborted the client with return code 232 (the 439 vs 1000 mismatch you quoted) before reaching its On the missing issue: three exist and all are closed, which is why the search came up empty. #118626 (yours, closed as completed on 2026-09-08, about 20 hours before the fix actually merged), #118831 and #118832 (closed as not planned). What is still open is the generic guard rather than this pair: #105942 resets enabled failpoints in |
…ns-push-down-nondeterministic
|
🕵 Merged The sole remaining red, Upgrade check (amd_release), is not caused by this pull request and a fix is already in progress — #113983, open since 2026-08-08. The single log line the check trips on is That table belongs to It is also rare rather than fleet-wide, which is why it had not surfaced here before. Over the last 30 days CIDB has exactly two occurrences of that message in
@groeneai, nothing separate is owed here as far as I can tell — but #113983 has been open for a month with no review, so if you can get it moving that would close this class of red for good. Thanks for the two answers above; both are settled. #118390 (merged |
|
Confirmed, and nothing separate is owed here. #113983 is the fix for that red, and your reading of it matches what I measured: the I have merged master into it and pushed The reason it stalled is that no review was ever requested on it: the only solicitation was a cc to @ leshikus at publication, which got no reply, and it has had no human review or comment in 35 days. Approving it once the run is green, or naming the reviewer you would rather have look at it, is the one step I cannot take myself. |
…ns-push-down-nondeterministic
|
🕵 Merged The which dropped all 20 downstream jobs. That is a private- The one remaining public red is Stress test (arm_tsan), and it is a parallel replicas coordinator exception: i.e. a It is also fleet-wide rather than specific to this branch. Over the last 30 days CIDB has 20 occurrences of that message, across 20 distinct pull requests and 7 different job flavours ( @groeneai, investigate this one and provide a fix in a separate pull request; if a fix is already in progress, link it here. I could not find an open issue — the only matching ones are closed and old (#65043, from 2024). On #113983: thank you for merging |
|
A fix is already open: #115786 ("Do not run the server-side AST fuzzer on a collaborative worker context"), open since 2026-08-21, no review on it yet. Mechanism, measured on this run's artifacts ( The chain from Lines 3 and 4 identify The frames in the stack are the initiator side, so they name whichever query happened to initiate that read, here a There is no open issue and I have not opened one; #115786 is the only tracking artifact today. I can file one if you want the signature tracked separately from the fix. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes how a WebAssembly UDF reports its query-scope determinism (so a non-DETERMINISTIC WASM UDF is no longer cloned below a join by use_join_disjunctions_push_down), plus two new stateless tests. None of the ClickBench queries use a join or a WASM UDF. The two flagged queries (Q28 and Q34) are single-table GROUP BY aggregations that cannot execute the changed code path, so their ~5% deltas are run-to-run variance, not a PR effect — Q28 is additionally an intrinsically noisy query. Q34's within-envelope suppression is consistent with the diff and stands. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…ns-push-down-nondeterministic
|
🕵 Thanks — the mechanism you traced (the server-side AST fuzzer firing on a query the node received as a parallel replicas worker, and the fuzzed copy announcing a second time under the borrowed replica number) explains why the signature spans job flavours and On the latest run ( |
…down respects their determinism `ExpressionInfoVisitor` only consulted `FunctionFactory`, so an `EXECUTABLE` or `WASM` user-defined function looked like an unknown function and was treated as deterministic. With `enable_analyzer = 0` and `enable_optimize_predicate_expression = 1`, `PredicateExpressionsOptimizer` then duplicated a predicate calling a non-`DETERMINISTIC` UDF into the subquery `HAVING` while keeping the outer copy, evaluating it twice per row and silently dropping rows, the same pattern ClickHouse#117249 fixed for the query-plan join disjunctions push-down. Resolve user-defined functions through `UserDefinedExecutableFunctionFactory` and `UserDefinedWebAssemblyFunctionFactory` first, the way `ActionsVisitor` and `TreeOptimizer` do. Follow-up to the review of ClickHouse#117249 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Closes: #116930
Related: #116939
Related: #116848
Related: #112700
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a WebAssembly UDF not declared
DETERMINISTICbeing treated as deterministic within a query, which let query plan optimizations such as the default-enableduse_join_disjunctions_push_downclone its call below a join and silently drop rows.Description
use_join_disjunctions_push_downextracts a per-side partial predicate and pushes it below the joinwith
addFilterOnTop, leaving the original filter in place. A conjunct that is not deterministicwithin the query is therefore drawn twice per row, independently, and only a row passing both draws
survives.
The
onlyDependsOnAvailableColumnsdeterminism check that this pull request originally added hassince landed on
masterthrough #112700, in a strongerform that also walks lambda bodies, so that hunk is dropped here and
masteris taken as is.What remains is the other half of the same defect, which is not fixed by that check.
FunctionUserDefinedWasmonly overrodeisDeterministic, so a WebAssembly UDF created withoutDETERMINISTICinheritedIFunction::isDeterministicInScopeOfQuery() == trueand was stillclassified as extractable — a module can keep state or read entropy, so this is wrong for every
optimization that relies on that predicate, not just this one.
ExecutableUDFs already answerfalsehere unconditionally. The override now returns the UDF's declared determinism.Tests:
05144_join_disjunctions_push_down_nondeterministicpins the plan forrand, for a statefulpredicate, and for the deterministic predicate that must still be pushed, plus the row-count band
that regressed from ≈500000 to ≈250000.
05145_join_disjunctions_push_down_wasm_udfcreates the same WebAssembly UDF twice, once plain andonce
DETERMINISTIC, and asserts that only the latter is cloned below the join.Workflow [PR]
Sync PR [sync-upstream/pr/117249]
Version info
26.9.1.1421(included in26.9and later)