Skip to content

AST fuzzer oracle: run sub-queries with Dynamic JOIN keys disallowed - #127078

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:oracle-no-dynamic-join-keys
Oct 21, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:oracle-no-dynamic-join-keys

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 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 when a query compares a Dynamic column with a non-Dynamic one in a join.

Description

AST fuzzer (amd_release, oracle) failed on the unrelated #109071 with a TLP Aggregate mismatch
(report)
on SELECT count() FROM big__fuzz_9, small__fuzz_1 WHERE (bid = sid) AND (v = sid), after the fuzzer had changed
the columns to v Dynamic and sid UInt256.

The fuzzer profile sets allow_dynamic_type_in_join_keys = 1, and the oracle sub-queries inherited it. The WHERE p
arm of the TLP rewrite then turns v = sid into a hash-join key on CAST(sid AS Dynamic), where a UInt64 value never
equals a UInt256 one, so the arm returns 0. The reference and the not(p) / isNull(p) arms keep a cross join with
an equals filter, which matches 200 pairs. These are the "unexpected results" #86358 cites for forbidding Dynamic
JOIN keys by default.

The change pins the setting off in QueryOracleChecker::makeOracleContext, next to the other settings that make
rewrite forms disagree by design. This also covers a session SET compatibility = '25.9', which turns it on. The fuzzed
query itself still runs with the setting on, so crash fuzzing of Dynamic join keys is kept. An oracle sub-query with an
explicit Dynamic JOIN key now fails with ILLEGAL_COLUMN and is skipped.

No test, as in #125003. Code: 906 mismatches in 40 fuzzed rounds of the seed query on the fuzzed schema, clickhouse local:

arm master this PR
setting on, make_distributed_plan = 0 18/40 0/40
setting on, make_distributed_plan = 1 20/40 0/40
compatibility = '25.9' 21/40 0/40
control: setting off 0/40 0/40

With this PR the TLP Aggregate oracle still runs on these queries and passes.

🤖 Generated with Claude Code


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

Version info

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

The fuzzer profile enables `allow_dynamic_type_in_join_keys`, and the
oracle context copied it. With it on, the TLP `WHERE p` arm turns a
`Dynamic = UInt256` equality into a hash-join key compared after a cast
to `Dynamic`, where a `UInt64` variant never equals a `UInt256` one, while
the reference and the `not(p)` / `isNull(p)` arms keep a cross join with
an `equals` filter. The forms then legitimately disagree (the limitation
documented by ClickHouse#86358) and the oracle reported a false mismatch on
`AST fuzzer (amd_release, oracle)`.

Pin the setting off in `makeOracleContext`, next to the other settings
that make rewrite forms disagree by design. It also overrides a session
`compatibility <= 25.9`, which turns the setting on. The fuzzed query
itself keeps the setting, so crash fuzzing of Dynamic join keys stays.

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 an own cold review (0 findings).
Nothing to adjudicate.

Session id: cron:clickhouse-review-slot-9:20261021-004100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 40 fuzzed rounds of the seed query on the fuzzed schema with clickhouse local give 18-21 Code: 906 mismatches on master in every run. The three TLP arms run by hand return 0 + 23081600 + 0 against a reference of 23081800 with the setting on.
b Root cause explained? The fuzzer profile sets allow_dynamic_type_in_join_keys = 1 and oracle sub-queries inherited it. The WHERE p arm turns v = sid into a hash-join key on CAST(sid AS Dynamic), where UInt64 never equals UInt256 (0 rows). The other arms keep equals (200 rows). This is the limitation documented by #86358.
c Fix matches root cause? Yes. The setting is pinned off in makeOracleContext, next to the existing pins of settings that make rewrite forms disagree by design. No product change.
d Test intent preserved / new tests added? No test, by rule for test-infrastructure changes (#125003). Validated locally. The nine fuzzer/oracle stateless tests pass.
e Both directions demonstrated? Yes. master 18/40, 20/40, 21/40 (setting on dp=0, dp=1, compatibility = '25.9') -> 0/40 each. Control with the setting off: 0/40 on both. With the fix the TLP Aggregate oracle logs passed.
f Fix is general across code paths? Yes. executeAndCollectSortedRows, executeScalar and executeWithSettings all start from makeOracleContext. DQP toggles neither this setting nor compatibility. Inline SETTINGS with it are already skipped.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Both gates use hasDynamicType (whole type tree), so Array/Tuple/Map of Dynamic are covered. Covered paths: an explicit JOIN ON (the oracle is skipped via ILLEGAL_COLUMN) and a WHERE equality turned into a key, with dp=0/1. Variant keys are not gated by this setting.
h Backward compatible? (maintainer-approved exception only) Yes. No default, format or user-visible change. Only internal oracle sub-queries are affected.
i Invariants and contracts preserved? Yes. The fuzzed query and fuzz_context keep the setting (measured: SELECT count() FROM d JOIN k256 ON d.v = k256.k still runs without error and returns 0). The pin is applied to the copied oracle context only, like every other pin.

Session id: cron:clickhouse-impl-slot-4:20261021-001100

@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 oracle sub-queries inherited the fuzzer profile's allow_dynamic_type_in_join_keys = 1, so the TLP WHERE p arm turned v = sid into a Dynamic hash-join key that matches nothing while the other arms kept equals; this pins the setting off in makeOracleContext only, the fuzzed query keeps it.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a67b057]

Summary: ✅


AI Review

Summary

The PR pins allow_dynamic_type_in_join_keys to false in QueryOracleChecker::makeOracleContext, preventing false oracle mismatches caused by different comparison semantics in JOIN keys and WHERE filters. The override applies to oracle subqueries while preserving the fuzzed query's settings. The reported before/after validation covers ordinary execution, distributed plans, and older compatibility settings. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 21, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 21, 2026
Merged via the queue into ClickHouse:master with commit 618b0fd Oct 21, 2026
527 of 529 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
@clickhouse-gh clickhouse-gh Bot added comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... and removed comp-testing Test content only (no production code). labels Nov 22, 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-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... 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