Skip to content

Keep DDL out of the AST fuzzer in 05234_constraint_scalar_subquery_over_distributed - #121952

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05234-keep-ddl-out-of-ast-fuzzer
Sep 24, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05234-keep-ddl-out-of-ast-fuzzer

Conversation

@groeneai

@groeneai groeneai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121418

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

Test-only change, no changelog entry required.

Description

Stress test (arm_asan_ubsan) failed with Cannot start clickhouse-server, the server dying on all
11 start attempts:

Load job 'load table test_2.t_scalar_constraint_user__fuzz_13' failed: Code: 393.
DB::Exception: There is no query or query context has expired ...
Cannot attach table `test_2`.`t_scalar_constraint_user__fuzz_13`

Failing jobs, the second on master:
https://github.com/ClickHouse/ClickHouse/actions/runs/35956719220/job/107532305130
https://github.com/ClickHouse/ClickHouse/actions/runs/35975552176/job/107563492694

t_scalar_constraint_user comes from the test I added in #121418. The stress profile sets
ast_fuzzer_any_query (tests/docker_scripts/stress_tests.lib:211), so the server-side AST fuzzer
replays DDL too, and it leaves a persisted copy of that table's scalar-subquery CHECK constraint
behind in two ways: a renamed __fuzz_N clone (QueryFuzzer.cpp:1395), which the test's own
DROP TABLE does not name, or a replay of that DROP as UNDROP TABLE (QueryFuzzer.cpp:7087),
which resurrects the original. The stress workers share a database that is never dropped, so the
leftover survives to the post-run restart, where the asynchronous metadata load has no query context
and cannot re-analyse the constraint. When stress_runner.sh:307 randomizes
async_load_databases = false, that load failure is fatal and the server never comes up, so the
whole job's signal is lost on an unrelated PR.

This pins ast_fuzzer_any_query = 0 for the test, which is the narrowest available pin: the gate at
executeQuery.cpp:3469 excludes every non-read-only statement, so no CREATE, DROP, DETACH or
ATTACH of this file is replayed, while its SELECTs are still fuzzed. Six existing tests pin the
same setting for the same class of leftover.

Validation: with the stress fuzzer profile installed and async_load_databases=0, the restart
refused to start in 6 of 6 runs before the change and came up in 6 of 6 after it, with no leftover
tables at all. 50/50 randomized runs pass.

The loader-side gap itself is pre-existing on master and is tracked by #96886 per @ alexey-milovidov's
ruling on #121418; it is not addressed here.


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

Version info

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

…er_distributed

The stress job installs its own fuzzer profile before the test phase
(tests/docker_scripts/stress_tests.lib:210-211 sets ast_fuzzer_runs and
ast_fuzzer_any_query), so the server-side AST fuzzer replays every successful
statement, DDL included: the eligibility gate at
src/Interpreters/executeQuery.cpp:3469 is
`if (!any_query && !isReadOnlyQuery(ast)) return;`.

That leaves a persisted copy of this test's scalar-subquery CHECK constraint
behind by either of two routes. A fuzzed CREATE is renamed
(src/Common/QueryFuzzer.cpp:1395), so the clone is not the name the test's own
DROP TABLE mentions; and a fuzzed DROP can be replayed as UNDROP TABLE
(src/Common/QueryFuzzer.cpp:7087), which resurrects the original. Nothing drops
either one: executeASTFuzzerQueries has no cleanup, the only caller of
QueryFuzzer::getDropQueriesForFuzzedTables is the client-side fuzzer in
programs/client/FuzzLoop.cpp:256, and the stress workers share a database that
is never dropped (ci/jobs/scripts/stress/stress.py:408 pins --database, and
tests/clickhouse-test:4343 then skips the per-test DROP DATABASE).

The leftover survives to the post-run restart at
tests/docker_scripts/stress_runner.sh:356. An asynchronous metadata load has no
query context (src/Databases/TablesLoader.cpp:80 copies the global context and
never calls makeQueryContext), so re-analysing the constraint throws
THERE_IS_NO_QUERY at src/Analyzer/Resolve/QueryAnalyzer.cpp:5509. In the half of
stress runs that stress_runner.sh:307-310 randomizes to
async_load_databases = false, that load failure is fatal rather than deferred
(programs/server/Server.cpp:3508-3510), so the server never starts and the whole
job's signal is lost on an unrelated PR.

ast_fuzzer_any_query = 0 is the narrowest pin that closes both routes, since the
gate above excludes every non-read-only statement while the test's SELECTs keep
being fuzzed. Six tests in the corpus already pin this setting for the same class
of leftover. The loader-side gap itself is pre-existing and tracked separately.

Measured with the stress fuzzer profile installed and async_load_databases=0:
before the change the restart refused to start in 6 of 6 draws (exit 210, zero
"Ready for connections"); after it, 6 of 6 came up with no leftover tables at
all, and the test passed 6 of 6 and 50 of 50 randomized runs.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 24, 2026
@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 of the resulting diff (2 nits, no blockers and no majors). No fix round was needed.

# Sev Finding Verdict Evidence / action
1 💡 The added comment says a CHECK constraint "reading a table function" cannot be analysed during the asynchronous load; the mechanism is broader than that AGREE, noted, not blocking True as written, but incomplete: the async loader has no query context at all (TablesLoader.cpp:80 copies the global context and never calls makeQueryContext, and QueryAnalyzer.cpp:5509 dereferences getQueryContext() unguarded), so any scalar subquery qualifies. Measured: the same Code: 393 reproduces with numbers(10), and one pre-fix draw died on t_scalar_constraint_pr__fuzz_6, whose constraint reads a plain local table. No behavioural effect, since the pin is file-scoped and invites no per-statement decision
2 💡 The plan's sibling-test enumeration named 3 corpus tests of this shape; a sweep finds 8 files AGREE, noted, not blocking The 4 unnamed files are not carriers, so the "out of scope" conclusion holds: 04054_ast_json_serialization.sql and 05226_ast_json_constraint_expression_argumentless_function.sql hold the constraint inside a parseQueryToJSON string literal, so no table is created; 05069_reject_array_join_in_check_constraint.sql and 05074_check_constraint_array_join_rejected.sql are rejected IN-subquery CREATEs

What I verified independently before reading the implementation's evidence:

  • Covers every carrier in one statement: executeQuery.cpp:3469
    (if (!any_query && !isReadOnlyQuery(ast)) return;) admits only
    SELECT/EXPLAIN/SHOW/DESCRIBE/EXISTS, and both fuzzer entry points (:3841, :4574) read
    the setting through that one gate, so no CREATE, DROP, DETACH, ATTACH or INSERT here is
    replayed and there is no bypass.
  • The SET cannot be refused in any lane: the stress profile marks <readonly/> on max_ast_depth
    and allow_experimental_window_view only; allow_feature_tier = 0 means "all changes allowed"
    (ServerSettings.cpp:1442) and no test or CI config sets it; and SettingsConstraints.cpp:374
    short-circuits an unchanged value, which is every non-stress lane. So no no-fasttest tag is
    owed, matching 04104 and 04305.
  • Necessary, not redundant: the harness's own ast_fuzzer_runs = 0 (tests/clickhouse-test:702) is
    scoped to clickhouse_execute_http, i.e. the hung check and log analysis, never the test body,
    and the setting is in no randomized-settings table.
  • Narrowest pin available, and narrower than 05024 and 05043, which pin ast_fuzzer_runs too
    and lose this file's SELECT fuzzing.
  • Carrier enumeration done independently before reading the plan and it matched: all eight table
    arms, the DETACH/ATTACH pair and the mid-file SET fall under the single file-scoped pin.
  • .reference untouched, the five expected lines unchanged, every assertion preserved, so the
    coverage this test was added for is not weakened.

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

Session id: cron:clickhouse-review-slot-8:20260924-100700

@clickhouse-gh clickhouse-gh Bot closed this Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local --path=D with SET ast_fuzzer_runs = 50, ast_fuzzer_any_query = 1, a CREATE TABLE whose CHECK holds a scalar subquery, then DROP TABLE; a second invocation on the same path is the restart and dies Code: 393 THERE_IS_NO_QUERY. End to end, the full stress rig refused to start in 6 of 6 runs
b Root cause explained? Yes. The stress profile sets ast_fuzzer_any_query (stress_tests.lib:211), so the gate at executeQuery.cpp:3469 lets DDL be replayed; the fuzzer then leaves a persisted copy of the constraint either as a __fuzz_N clone (QueryFuzzer.cpp:1395) or by replaying the DROP as UNDROP TABLE (QueryFuzzer.cpp:7087). The stress workers share a database that is never dropped, so it survives to the post-run restart, whose async load has no query context (TablesLoader.cpp:80) and throws at QueryAnalyzer.cpp:5509. With async_load_databases = false (stress_runner.sh:307) that is fatal at Server.cpp:3508-3510
c Fix matches root cause? Yes. The cause is that this test's DDL is replayed, and ast_fuzzer_any_query = 0 is exactly the gate that excludes non-read-only statements. No bound widened, no dataset reduced, no blanket no-random-* tag, no guard at the failure site
d Test intent preserved / new tests added? Yes. All five assertions and all eight table arms are unchanged, .reference is unchanged, and the test's SELECTs are still fuzzed. No new test is owed: the artifact under repair is the test, and a stateless test cannot restart a server, so the property is proven by the A/B below
e Both directions demonstrated? Yes. Mechanism tier: 7/8 runs red before, 0/10 after, with a negative control that reddens again when the setting is flipped back. Full rig, 6 draws each: restart refused 6/6 before and came up 6/6 after; the test itself went 6/6 FAIL to 6/6 OK, leaving 0 tables
f Fix is general across code paths? Yes for this file: one gate covers all eight arms and both leftover routes, and the { serverError } arms are never fuzzed since the fuzzer is a finish callback of a successful pipeline. Sibling corpus tests of this shape (04908, 02841, 03594) are out of scope with 0 CIDB occurrences, and 04908 fails loudly rather than silently
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for a setting pin, which adds no input surface. The underlying loader gap was checked anyway and is input-agnostic: it fires for remote(), for numbers(10), and for a plain local table, which is why the pin sits above every arm rather than per arm
h Backward compatible? (maintainer-approved exception only) Yes. No default changes, so no SettingsChangesHistory.cpp entry is owed. Both settings landed in 26.2, older than any binary the upgrade or compatibility lanes use, so no UNKNOWN_SETTING
i Invariants and contracts preserved? Yes. The file's only session-scope assumption (its mid-file SET must reach the next statement) is unchanged. The invariant added is that no statement of this test can leave a persisted table the async loader cannot analyse: measured as 0 leftover tables in 6/6 post-fix draws, including the error and early-return arms and the final DROPs

Session id: cron:clickhouse-impl-slot-5:20260924-092000

@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [05c97cd]

Summary: ✅


AI Review

Summary

This PR makes 05234_constraint_scalar_subquery_over_distributed disable server-side AST fuzzing for non-read-only statements by setting ast_fuzzer_any_query = 0 at file scope, which prevents stress runs from replaying this file's DDL and leaving behind restart-breaking tables. I found no unresolved correctness, coverage, or metadata issues: the SET takes effect before the finish callback snapshots the fuzzer settings, so the file still fuzzes its SELECTs while skipping the problematic DDL replay, and the linked CI is all green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 24, 2026
@groeneai
groeneai requested a review from PedroTadim September 24, 2026 10:37
@PedroTadim PedroTadim self-assigned this Sep 24, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 24, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Sep 24, 2026
Merged via the queue into ClickHouse:master with commit 715315f Sep 24, 2026
172 of 341 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

This pin did what it was measured to do, but it was not sufficient: the AST fuzzer is not the only thing that leaves the table behind. Master went red again at 17:13Z on 2b5b353e495c8599597b016da021d8141e6da734, which contains this merge (compare reports ahead_by=166), and the leftover was the original t_scalar_constraint_user, with no __fuzz_N clone anywhere in that job.

The cause of that one, from the run's own server log: the stress runner sets ignore_drop_queries_probability = 0.2, and InterpreterDropQuery (:219-227) turns a DROP TABLE on a table that stores data on disk into a silent no-op that reports success. The log shows Ignore DROP TABLE query for table ... t_scalar_constraint_user right after the test issued it. The file issues 7 drops, so the chance that at least one is ignored is about 0.79.

I opened #122101, which removes the class rather than one carrier: the test's tables now live in a Memory database, which never writes table metadata, so no leftover can be replayed at startup even if the teardown never runs, and DROP DATABASE is the one drop the stress profile never ignores. 6/6 restarts refused before, 6/6 clean after.

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-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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