Skip to content

Add a test for EXPLAIN AST optimize = 1 with an IN subquery over remote in PREWHERE - #124634

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:test-explain-ast-optimize-prewhere-in-remote
Oct 10, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:test-explain-ast-optimize-prewhere-in-remote

Conversation

@groeneai

@groeneai groeneai commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121639
Related: #117253
Related: #121464

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

This adds the minimal case from #117253 as a regression test for the EXPLAIN path of the StorageDistributed::read null dereference that #121639 fixed. None of the tests in #121639 goes through EXPLAIN.

EXPLAIN AST optimize = 1 analyses the query with the interpreter that preceded the analyzer. That interpreter builds the set of an IN subquery in PREWHERE (appendPrewhere -> ActionsMatcher::makeSet). Before #121639 the set's plan for remote(...) reached StorageDistributed::read without a PlannerContext. The test reads the explained AST through SELECT ... FROM (EXPLAIN ...): * must be expanded, which proves the analysis ran, and Function remote must still be in the AST.

Validation: on a master build without #121639 (44b568f4) the test segfaults the debug binary, and ASan+UBSan reports member call on null pointer of type 'DB::PlannerContext' at StorageDistributed.cpp:1036. On master it prints 0 1 and passes 50/50 runs with randomized settings.

CI report of the original failure: AST fuzzer (amd_release, oracle) on #117253

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1987-master (included in 26.10 and later)

…te in PREWHERE

`EXPLAIN AST optimize = 1` analyses the query with the interpreter that preceded the
analyzer, and `appendPrewhere` builds the set of an `IN` subquery in `PREWHERE`. Before
ClickHouse#121639 that set was planned without a query tree, so reading `remote` through
`StorageDistributed::read` dereferenced a null `PlannerContext`. None of ClickHouse#121639's tests
goes through `EXPLAIN`, so this adds the minimal case from ClickHouse#117253.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117253&sha=546cd65f39602b759209f1649d527c047d1bc250&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29

Related: ClickHouse#121639
Related: ClickHouse#117253

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 8, 2026
@groeneai

groeneai commented Oct 8, 2026

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 (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 The test's header comment says the old path dereferenced a null query tree; the null object was the PlannerContext (StorageDistributed.cpp, buildQueryTreeDistributed) AGREE noted, not blocking (comment wording only, no code or test behaviour involved)

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261008-132400

@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE t (x UInt64) ENGINE = MergeTree ORDER BY x; EXPLAIN AST optimize = 1 SELECT * FROM (SELECT x FROM t PREWHERE x IN (SELECT x FROM remote('127.0.0.1', currentDatabase(), t))); crashes a master build without #121639 on every run, with no settings involved.
b Root cause explained? EXPLAIN AST optimize = 1 runs the old interpreter. appendPrewhere -> ActionsMatcher::makeSet then planned the IN subquery without a query tree, so StorageDistributed::read dereferenced a null PlannerContext. #121639 plans it through the analyzer.
c Fix matches root cause? The engine fix is #121639, which is merged. This PR only adds the missing test for the EXPLAIN entry point.
d Test intent preserved / new tests added? New test 05339. It asserts that * was expanded (so the analysis that builds the set ran) and that Function remote is still in the explained AST.
e Both directions demonstrated? Pre-fix master 44b568f4: debug binary SIGSEGV in StorageDistributed::read <- makeSet <- appendPrewhere <- ExplainAnalyzedSyntaxMatcher; ASan+UBSan member call on null pointer of type 'DB::PlannerContext'. Master with #121639: 0 1, runner OK, 50/50 randomized.
f Fix is general across code paths? N/A, test only. EXPLAIN SYNTAX of a non-SELECT reaches the same makeSet call and is covered by the same engine fix.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A, test only. An explicit PREWHERE does not depend on the prewhere-moving settings, and 50 randomized runs pass.
h Backward compatible? (maintainer-approved exception only) Yes, test only.
i Invariants and contracts preserved? N/A, no source change.

Session id: cron:clickhouse-impl-slot-7:20261008-130122

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7c90c8d]

Summary: ✅


AI Review

Summary

This PR adds one stateless regression test for the EXPLAIN AST optimize = 1 path that previously reached StorageDistributed::read through PREWHERE ... IN (SELECT ... FROM remote(...)) without a valid planner context. I reviewed the full diff, the current implementation of the EXPLAIN AST optimization path in InterpreterExplainQuery, the relevant PREWHERE/set-building code, and the prior PR discussion. I did not find a blocker or major issue in the current change set.

Missing context / blind spots
  • ⚠️ I did not replay the new stateless test locally because this checkout has no existing build_* directory or test binary to run it against; the fast test and style checks on the PR are green, but the full build matrix was still pending at review time.
Final Verdict

✅ No blocking or major findings.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 8, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 9, 2026
Merged via the queue into ClickHouse:master with commit ef9b249 Oct 10, 2026
152 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 10, 2026
@clickhouse-gh clickhouse-gh Bot added comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). 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-distributed Distributed table engine & query routing across shards (sharding/load balancing). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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