Skip to content

Skip the JSON and Dynamic storage-layout functions in the AST fuzzer oracles - #126703

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:oracle-skip-json-dynamic-layout-functions
Nov 1, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:oracle-skip-json-dynamic-layout-functions

Conversation

@groeneai

@groeneai groeneai commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Stop the AST fuzzer oracles from reporting false mismatches on JSONDynamicPaths, byteSize and the other functions whose result depends on how a JSON or Dynamic value is stored.

Description

AST fuzzer (amd_release, oracle) failed on the unrelated #120579 with a NoREC mismatch
(report):
... JOIN inner_json_shared AS l ON l.a = r.x WHERE NOT has(JSONDynamicPaths(l.a), 'x') returned 1 row, its
countIf form 0.

JSONDynamicPaths, JSONDynamicPathsWithTypes, JSONSharedDataPaths, JSONSharedDataPathsWithTypes and
isDynamicElementInSharedData report where a value is stored (its own subcolumn or shared data), not the value, and
byteSize measures that representation. The hash join returns a required right key rebuilt from the left key, so l.a
keeps x in shared data below the join and has it as a dynamic path above it: the filter pushed below the join and
countIf above it are entitled to differ. Marking these non-deterministic instead would stop existing tables keyed on
one from loading. No other deterministic function in system.functions differs for equal values stored both ways.

The change, in QueryOracleChecker.cpp:

  • the six names join the set of functions the oracles skip;
  • the bare-name screen (arrayMap(f, arr), {p:Identifier}) also consults that set for a name that resolves to a
    regular function. It read only isDeterministic(), so arrayMap(materialize, [k]) was checked.

No query behaviour changes and no test, as in #125003. Oracle checks per 30 fuzzed rounds of each seed:

seed query uses master: checked / Code: 906 this PR: checked with it
a JSON*Paths* function 10-20 / 10-16 0
isDynamicElementInSharedData 15 / 0 0
byteSize, call / arrayMap form 12 / 12, 13 / 11 0
arrayMap(JSONDynamicPaths, ...) 4 / 4 0
arrayMap(materialize, ...) 17 / 0 0
controls: JSONAllPaths, a column named url 12, 18 / 0 10-19, 16-19 checked

#117187 adds the five names inside a larger refactor, without byteSize or the bare-name change.


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

Version info

  • Merged into: 26.11.1.1055-master (included in 26.11 and later)

…oracles

`JSONDynamicPaths`, `JSONDynamicPathsWithTypes`, `JSONSharedDataPaths`,
`JSONSharedDataPathsWithTypes` and `isDynamicElementInSharedData` report
where a value is stored (its own subcolumn or shared data), which is a
property of the column, not of the value. The hash join emits a required
right key as a copy of the left key (`copyLeftKeyColumnToRight`), so the
same right key has a different layout below and above the join, and
NoREC compared a filter pushed below the join with `countIf` evaluated
above it (`AST fuzzer (amd_release, oracle)` on PR ClickHouse#120579). The engine
does the same for `isConstant`, which the oracles already skip because
it is not deterministic.

Add the five names to the backstop set. Also make
`namesNonDeterministicRegularFunction` consult that set for a name that
resolves to a regular function: the bare-name screen (a function passed
by name to a higher-order function, or a `{param:Identifier}` holding
one) read only `isDeterministic()`, so set members such as `materialize`
passed in `arrayMap(materialize, arr)` form. Gating the lookup on
`FunctionFactory::tryGet` keeps columns named like a table or aggregate
function in the set (`url`, `sum`) checked.

Marking the five non-deterministic instead was rejected: a sorting or
partition key using one of them, which is accepted today, would then be
rejected, and an existing table keyed on one would stop loading.
ClickHouse#117187 carries the same five entries inside a larger oracle refactor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (0 findings).
The plan-stage review found one gap before implementation: the bare-name screen (arrayMap(f, arr),
{p:Identifier}) never consulted the skip set. It is the second bullet of this PR.

Session id: cron:clickhouse-review-slot-10:20261019-123400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On master, 30 fuzzed rounds per seed (ast_fuzzer_runs = 1, ast_fuzzer_oracle = 1) give NoREC Code: 906 for each JSON*Paths* seed (10 to 16 of 30); the report's query returns 1000 rows with query_plan_filter_push_down = 1, 0 with = 0.
b Root cause explained? The five report where a value is stored, not the value; the hash join rebuilds the right key from the left key, so the layout differs below and above the join. They were not in the oracle's skip set, and the bare-name screen did not consult that set.
c Fix matches root cause? Yes. The oracle screen now skips the five in every spelling (call, bare name, query parameter, APPLY); no engine change (isConstant behaves the same and is already skipped).
d Test intent preserved / new tests added? No new test: the oracle is a testing tool (#125003). 04658_ast_fuzzer_oracle_tlp_aggregate_counter (10/10) and 05339_ast_fuzzer_oracle_distributed_plan_read_cap (6/6) pass.
e Both directions demonstrated? Master: 55 mismatches in 300 rounds. This PR, 3 runs of 300 rounds: 0 mismatches, 0 checked rounds with any of the five (or bare materialize); controls JSONAllPaths and a column named url stay checked.
f Fix is general across code paths? All four places the screen sees a function name go through namesNonDeterministicRegularFunction, which all nine oracles run; the bare-name change also covers materialize, indexHint, throwIf, initializeAggregation.
g Fix generalizes across inputs (params/datatypes/wrappers)? Case-insensitive lookup on the spelling and the resolved name; no aliases. Value-level siblings (JSONAllPaths, JSONAllValues, dynamicType) stay checked.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or query behaviour change; only the experimental ast_fuzzer_oracle path is affected.
i Invariants and contracts preserved? namesNonDeterministicRegularFunction still returns true for every name it did before (new clauses are OR-ed); a column named like a table or aggregate function in the set stays checked (gated on FunctionFactory::tryGet).

Session id: cron:clickhouse-impl-slot-41:20261019-121700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @qoega @PedroTadim, could you review this and add the can be tested label so CI runs? The oracles now skip JSONDynamicPaths and the four other functions that report where a JSON or Dynamic value is stored (the hash join rebuilds the right key from the left key, so NoREC compared two layouts), and the bare-name screen now also consults the skip set.

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5c55872]

Summary: ✅


AI Review

Summary

Reviewed PR #126703 at 5c5587227f403f05d851fddbe255a70ff2593397, including all prior discussion. The change prevents false AST fuzzer oracle mismatches from JSON/Dynamic storage-layout functions and byteSize, and applies the same exclusions to regular functions referenced by name. No actionable findings remain.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 19, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Oct 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 19, 2026
"indexHint",
/// These report whether a `JSON` path or a `Dynamic` value has its own subcolumn or sits in shared data,
/// which depends on the column holding the value (a join or a merge can change it), not on the value.
"JSONDynamicPaths", "JSONDynamicPathsWithTypes", "JSONSharedDataPaths", "JSONSharedDataPathsWithTypes",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai are you sure no other functions are missing? There are many JSON functions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't checked that exhaustively, so I did: every non-alias function in system.functions (about 1,700, scalar and aggregate, with up to two constant extra arguments) over rows holding the same JSON/Dynamic value stored both ways (own subcolumn or variant vs shared data). Apart from these five, the only deterministic function whose result differs is byteSize (52 vs 25 bytes for {"x":1}). It gives the same NoREC mismatch over this join on master (12 of 12 checked rounds), so I added it in 5c55872. blockSerializedSize and dumpColumnStructure differ as well, but they are already non-deterministic. The JSONExtract*, JSON_*, simpleJSON*, JSONAllPaths*, dynamicType and distinctJSONPaths* functions all return equal results.

if (const auto resolver = FunctionFactory::instance().tryGet(name, context))
if (!resolver->isDeterministic())
if (!resolver->isDeterministic()
|| nonDeterministicFunctionsLower().contains(Poco::toLower(name))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai this is tricky, it could make deterministic functions labeled as non deterministic?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only inside the oracle. This helper feeds only hasNonDeterministicFunctions, whose sole use is to skip an oracle check, so a false positive costs one unchecked query, never a false mismatch. isDeterministic() and system.functions are unchanged.

For calls f(x) it changes nothing, because isOracleUnsafeFunctionName already looks the name up in this set. It makes the bare-name form arrayMap(materialize, arr) behave like arrayMap(x -> materialize(x), arr). Measured in system.functions (no aliases resolve to them), the names it newly screens are the five layout functions, byteSize, indexHint, initializeAggregation, materialize and throwIf; a column with one of those names also skips its query. The aggregate and table-function members (sum, url, ...) are not regular functions, so columns named like them stay checked.

`byteSize` of a `JSON` or `Dynamic` value counts the bytes of its in-memory
representation, so it changes with the same storage layout (own subcolumn vs
shared data) as the five functions added in the previous commit. Over the join
from the original report, `WHERE byteSize(l.a) > 30` returns 20 rows with
filter push-down and 0 with `query_plan_filter_push_down = 0`, and the oracle
reported `Code: 906` in 12/12 and 11/13 checked rounds (call and bare-name
form) on master; 0 with this change.

A scan of every function in `system.functions` over rows holding identical
`JSON`/`Dynamic` values in different layouts found no other deterministic
function whose result changes (`blockSerializedSize` and `dumpColumnStructure`
differ too, but are already non-deterministic).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). and removed comp-testing Test content only (no production code). labels Oct 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5c5587227 with master 80010618b (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of ed21581f8; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 1, 2026
Merged via the queue into ClickHouse:master with commit cf22f7c Nov 1, 2026
178 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants