Skip to content

AST fuzzer oracle: skip SEMI joins like ANY joins - #127260

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:ast-fuzzer-oracle-skip-semi-joins
Oct 26, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:ast-fuzzer-oracle-skip-semi-joins

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124149

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):

...

Description

05339_ast_fuzzer_oracle_distributed_plan_read_cap failed twice with TLP WHERE oracle mismatch on a fuzzed SEMI RIGHT JOIN (amd_tsan, s3 storage, targeted, arm_asan_ubsan, targeted), both in the targeted jobs of #126945. In both, the two sides have the same row count and differ only in the left table's id.

Root cause. A SEMI join takes the other side's columns from an arbitrary matching row, like ANY: RIGHT SEMI runs the same hash-join branch as RIGHT ANY, where the first left row that probes a key is used for all of its right rows. TLP WHERE runs the reference and its three partitions as separate queries, and each one can pick a different row. hasNonDeterministicJoinAnywhere skips ASOF and ANY joins for this reason, but not SEMI.

Change. Skip SEMI joins in the same check, as #124149 did for ANY. It covers the query, its subqueries and the stored definitions it reads. ANTI is still checked: the other side's columns are always defaults (or NULL with join_use_nulls), so no row is picked. The open #117187 keeps SEMI eligible as deterministic; that holds only for the preserved side's columns, and both failures read the other side's id.

Validation. At max_threads = 3 the reference query returns a different left id from run to run (5 values in 8 runs). The oracle runs its sub-queries with max_threads = 1, where master happens to pick the same row each time, so in 40 local rounds the mismatch did not appear on master. In the same rounds, 219 SEMI queries reached TLP WHERE without the change and 0 with it, while ANTI and join-free queries are still checked. With the change, 05339 passed 50 of 50 randomized runs. No new test, as for #124149.


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

Version info

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

A SEMI join takes the other side's columns from an arbitrary matching
row, like ANY: RIGHT SEMI runs the RIGHT ANY hash-join branch, where the
first left row that probes a key is used for all of its right rows, and
LEFT SEMI keeps one stored right row per key. TLP WHERE runs the
reference and its three partitions as separate queries and each one
picks again, so an exhaustive partition can disagree on those columns.
`hasNonDeterministicJoinAnywhere` skipped ASOF and ANY joins for this
reason but not SEMI, and 05339 reported a false `TLP WHERE oracle
mismatch` on a fuzzed `SEMI RIGHT JOIN` in two targeted CI jobs.

On master the pick happens to be stable at the `max_threads = 1` the
oracle uses for its sub-queries (the mismatch did not appear in 40 local
rounds), but at `max_threads = 3` the reference query returns a
different left `id` from run to run, and SEMI semantics allow any
matching row.

ANTI stays eligible: the other side's columns are always defaults (or
NULL with `join_use_nulls`), so no row is picked.

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 (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 The open #117187 calls SEMI deterministic, and this PR reverses that AGREE One sentence in the description: it holds only for the preserved side's columns.
2 💡 Every SEMI query is skipped, including shapes that read only the preserved side DISAGREE Same trade as the ANY screen in #124149: the AST cannot reliably tell which side an unqualified column comes from in a self-join. ANTI is still checked.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261021-191300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The gap, yes: without the change every fuzzed SEMI query reaches TLP WHERE (219 in 40 local rounds of 05339's seeds), and the oracle's own reference and partition queries disagree in 6 of 8 runs at max_threads = 3. The mismatch itself did not appear on master locally: the oracle runs sub-queries with max_threads = 1, where master picks the same row every time.
b Root cause explained? SEMI takes the other side's columns from an arbitrary match (RIGHT SEMI shares the RIGHT ANY hash-join branch). TLP WHERE executes the reference and three partitions separately, each picks again, and hasNonDeterministicJoinAnywhere screened only ASOF and ANY.
c Fix matches root cause? Yes. The screen is where the oracle records that a join's matched row is plan-dependent; the same predicate serves the top-level gate and stored definitions.
d Test intent preserved / new tests added? No new test: the oracle is a testing tool (its stateless tests were removed in #125003; #124149 added the ANY screen without one). 05339 still checks TLP Aggregate and NoREC, 50 of 50 randomized runs.
e Both directions demonstrated? 219 SEMI queries reach TLP WHERE without the change, 0 with it (210 skipped); ANTI (149 / 159) and join-free (198 / 206) queries are still checked.
f Fix is general across code paths? It is the only strictness check in QueryOracleChecker.cpp; it recurses into subqueries, CTEs and IN (SELECT ...), and the stored-definition screen calls it too.
g Fix generalizes across inputs (params/datatypes/wrappers)? Any SEMI kind (strictness-only test), GLOBAL, every join algorithm (AST level). join_default_strictness cannot produce SEMI. ANTI measured deterministic with and without join_use_nulls.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, no server behavior change; only the experimental oracle skips more queries.
i Invariants and contracts preserved? The oracle no longer compares a query whose join output comes from an arbitrary match, now including SEMI. The change only widens an existing skip path.

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

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim @qoega, could you review this and add the can be tested label so CI runs? The oracle's non-deterministic join screen skipped ASOF and ANY but not SEMI, whose other-side columns come from an arbitrary matching row, so TLP WHERE compared two different picks (seen in 05339); this adds SEMI to the same screen, as #124149 did for ANY.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d71895e]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, sequential) FAIL
05218_text_index_substreams_opened_lazily FAIL cidb IGNORED

AI Review

Summary

The PR excludes SEMI joins from the AST fuzzer oracle's comparisons because columns from the filtering side can come from an arbitrary matching row. The existing recursive check also covers subqueries and stored definitions. No actionable findings in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 21, 2026
@PedroTadim PedroTadim self-assigned this Oct 21, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Oct 21, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a41c5d7

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) infra, not from this PR (it changes only the oracle's join screen in QueryOracleChecker.cpp): the upgraded server logged BackupsWorker: Failed to make internal backup ... 02907_backup_mv_with_no_source_table ... Got error from the initiator ... Query was cancelled (Code 394) for an ON CLUSTER entry the previous release's stress phase left in the DDL queue; the same line failed this check on 12 other PRs in 30 days #125562 (mine, open)
Mergeable Check, PR praktika rollups of the row above #125562 (the owner of the row above)

The Config Workflow / Pre Hooks failure on this head is the earlier attempt stopped at the can be tested label; the current attempt passed. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261021-233002

@PedroTadim
PedroTadim enabled auto-merge October 26, 2026 11:22
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 26, 2026
Merged via the queue into ClickHouse:master with commit a8fbea0 Oct 26, 2026
176 of 178 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 26, 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.

3 participants