Repository navigation
AST fuzzer oracle: skip queries with WITH TOTALS in a subquery or view - #127335
Conversation
A `WITH TOTALS` inside a FROM subquery, a CTE, a JOIN side or a view body puts a totals block into the outer query's result, which the oracles compare. That block is not distributive over a WHERE partition: a filter pushed below `TotalsHavingStep` recomputes the totals over the filtered rows (deliberately, see filterPushDown.cpp), and `UNION ALL` keeps the totals of its first branch only (`Pipe::uniteTotals`). So TLP WHERE's reference and its partitioned union disagree on the totals row, and the same holds for TLP DISTINCT and the distributed-plan oracle. The oracles already rejected a top-level `WITH TOTALS`. Add a recursive `hasWithTotalsAnywhere` screen to `check()`, next to the FINAL and WITH FILL screens, and to the stored-definition screen so a view hiding the same text is skipped too. Nested ROLLUP / CUBE / GROUPING SETS without TOTALS are left checked: their data rows stay partitionable. Seen on PR ClickHouse#110321 in `AST fuzzer (amd_release, oracle)`; reproduces on master. Mismatching attempts (10 fuzzed rounds each, clickhouse local), master build vs this change: subquery 44/50 -> 0/50, view 45/50 -> 0/50, CTE 46/50 -> 0/50, JOIN 26/30 -> 0/30. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the hasWithTotalsAnywhere comment to two lines; drop the clause narrating why the check recurses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; 1 full pass). Session id: cron:clickhouse-review-slot-8:20261022-062600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261022-060200 |
|
cc @PedroTadim @qoega, could you review this and add the |
|
Workflow [PR], commit [6b14e94] Summary: ✅
AI ReviewSummaryPR #127335 prevents false AST fuzzer oracle mismatches by screening for Final VerdictStatus: ✅ Approve |
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, 12 s compile time in total, 7 of them have a recent master baseline. |
238ca00
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Stop the AST fuzzer oracles from reporting false mismatches for queries that read a
WITH TOTALSresult through a subquery, a CTE, a JOIN or a view.Description
AST fuzzer (amd_release, oracle)failed on an unrelated PR with a TLP WHERE mismatch(report)
on
SELECT x, y, x, y FROM (SELECT DISTINCT -1 AS y, isNotNull(true AS x), 1 AS x, x GROUP BY GROUPING SETS ((y)) WITH TOTALS LIMIT 376) WHERE isNull(x).A
WITH TOTALSin a subquery puts a totals block into the outer result, and it is not distributive over a WHEREpartition: a filter pushed below
TotalsHavingSteprecomputes the totals over the filtered rows (by design), andUNION ALLkeeps the totals of its first branch only (Pipe::uniteTotals). WithT = (SELECT n % 3 AS y, count() AS c FROM t GROUP BY y WITH TOTALS)over 6 rows,SELECT y, c FROM Thas totals0 6and the TLP union overy = 1has0 2.The change applies a recursive
hasWithTotalsAnywhereinQueryOracleChecker::check()and to stored view bodies. Nested
ROLLUP/CUBE/GROUPING SETSwithoutTOTALSstay checked. Thetruevs1half of the mismatch is a separate analyzer issue (
true AS xand1 AS xaccepted as one alias, addressed by#117161) and stays visible to the oracle. #117187 has a wider screen; this is the minimal fix.
No test, as in #125003.
Code: 906mismatches per attempt of 10 fuzzed rounds:TOTALSTOTALSTOTALSTOTALSTOTALSsubqueryGROUP BY, noTOTALSTOTALS)🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127335]
Version info
26.11.1.548-master(included in26.11and later)