Skip to content

AST fuzzer oracle: gate non-deterministic constructs found by fuzzing - #117347

Closed
qoega wants to merge 2 commits into
masterfrom
oracle-nondeterminism-gates
Closed

qoega wants to merge 2 commits into
masterfrom
oracle-nondeterminism-gates

Conversation

@qoega

@qoega qoega commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Live fuzzing of master surfaced several classes of false AST-fuzzer oracle mismatch —
each a construct whose result is not stable across the oracle's metamorphic rewrites,
so the reference and the rewrite legitimately differ. This gates them so the oracle
stops reporting them as mismatches (each verified with a 60–100-run zero-mismatch soak,
while an eligible control query still exercises the oracle):

  • approx_top_k / approx_top_sum (alias approx_top_count) use the same bounded
    Filtered-Space-Saving structure as topK: merging the partial states from the TLP
    UNION-ALL partition split drops different candidates than a single pass, so the
    approximate result differs. Added to non_deterministic_functions.
  • Buffer-engine tables split rows between an in-memory buffer and the backing table
    with a background flush, so two reads can return different rows. Generalised the
    Distributed gate to a non_deterministic_table_engines set covering both.
  • ANY / RightAny joins pick an arbitrary matching right row, so which row survives
    is plan-dependent. Generalised the ASOF-join gate to also cover them.
  • JSONDynamicPaths / JSONSharedDataPaths(WithTypes) / isDynamicElementInSharedData
    expose the physical dynamic-vs-shared storage split of a JSON column (decided per
    part/block under max_dynamic_paths), not the logical value; a rewrite that
    re-materialises the column reports a different split. Gated.
  • WITH TOTALS / ROLLUP / CUBE / GROUPING SETS synthesise a subtotal/grand-total
    row that is a global aggregate, not distributive over the WHERE/HAVING partition
    split. The per-oracle guards only rejected a top-level modifier; a new recursive
    hasGroupByTotalsModifierAnywhere gate also catches one hidden in a CTE/subquery.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Related: #99980


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

qoega and others added 2 commits August 31, 2026 08:27
…zzing

Live fuzzing of master surfaced four classes of false oracle mismatch — each a
construct whose result is not stable across the oracle's metamorphic rewrites,
so the reference and the rewrite legitimately differ:

* approx_top_k / approx_top_sum (alias approx_top_count) use the same bounded
  Filtered-Space-Saving structure as topK: merging the partial states from the
  TLP UNION-ALL partition split drops different candidates than a single pass,
  so the approximate result differs. Added to non_deterministic_functions next
  to topK (stripAggregateCombinators maps the *State/*Merge forms back).

* Buffer-engine tables split rows between an in-memory buffer and the backing
  table with a background flush thread, so two reads can return different rows.
  Generalised referencesDistributedTableAnywhere to a non_deterministic_table_
  engines set covering both Distributed and Buffer.

* ANY / RightAny joins pick an arbitrary matching right row, so which row
  survives is plan-dependent. Generalised hasAsofJoinAnywhere to also gate them.

* JSONDynamicPaths / JSONSharedDataPaths(WithTypes) / isDynamicElementInShared-
  Data expose the physical dynamic-vs-shared storage split of a JSON column,
  decided per part/block under max_dynamic_paths, not part of the logical value;
  a rewrite that re-materialises the column reports a different split.

Verified: a zero-mismatch soak (60-100 fuzzed runs each) over every construct,
while an eligible control query still exercises the oracle (ProfileEvent checks
delta 117 vs 0 for the gated seeds).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nywhere

A GROUP BY totals/subtotal modifier synthesises a grand-total or subtotal row
that is a global aggregate, not a per-input-row value, so it is not distributive
over the WHERE/HAVING partition split the metamorphic oracles perform: each
partition re-scans the source and recomputes (or drops) the totals row, so it
legitimately differs from the reference. The per-oracle guards already reject a
top-level `group_by_with_totals`, but a modifier hidden in a CTE or subquery
(whose outer query the oracle rewrites) slipped past them. Fuzzing surfaced this
as a TLP WHERE mismatch on `... FROM (SELECT ... GROUP BY g WITH TOTALS) WHERE
NULL > cnt`: the totals row read (0,500) directly but (0,0) through the split.

Add a recursive `hasGroupByTotalsModifierAnywhere` gate at the top of check().
Verified: zero mismatches over a 60-run soak and a 0 check-counter delta for the
WITH TOTALS seed, while an eligible non-totals query still exercises the oracle.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [75eef80]

Summary: ❌

job_name test_name status info comment
Config Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/pr_labels_and_category.py FAIL
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/pr_body_check.py FAIL
Dockers Build (amd) DROPPED
Dockers Build (arm) DROPPED
Dockers Build (multiplatform manifest) DROPPED
Style check DROPPED
Code Review DROPPED
Docs check (Mintlify) DROPPED
Fast test DROPPED
Fast test (arm_darwin) DROPPED

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant