Skip to content

Host the tables of 05234_constraint_scalar_subquery_over_distributed in a Memory database - #122101

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05234-no-persisted-constraint-subquery
Sep 25, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05234-no-persisted-constraint-subquery

Conversation

@groeneai

@groeneai groeneai commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121418
Related: #121952

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 (*_asan_ubsan) failed with Cannot start clickhouse-server, the server dying on all 11
start attempts:

Load job 'load table test_w3m7r6a4k3o0.t_scalar_constraint_user' failed:
Code: 393. There is no query or query context has expired ...

Failing jobs (last two on master):
https://github.com/ClickHouse/ClickHouse/actions/runs/35956719220/job/107532305130
https://github.com/ClickHouse/ClickHouse/actions/runs/35975552176/job/107563492694
https://github.com/ClickHouse/ClickHouse/actions/runs/36030675501/job/107744083942

t_scalar_constraint_user is from the test I added in #121418. #121952 closed the AST-fuzzer
route; this failure took another. The stress runner passes ignore_drop_queries_probability=0.2
(stress.py:528): a DROP TABLE on a disk-backed table then becomes a silent no-op that reports
success (InterpreterDropQuery.cpp:219-227), so the table survived to the post-run restart:

(query 17, line 26) DROP TABLE t_scalar_constraint_user;
InterpreterDropQuery: Ignore DROP TABLE query for table test_w3m7r6a4k3o0.t_scalar_constraint_user

The asynchronous metadata load has no query context, so a CHECK constraint whose scalar subquery
reads a table function cannot be analysed; with async_load_databases = false that is fatal. Two
more routes reach the same state and no SET reaches either: a failed ATTACH leaves the metadata
file while the test's own DROP then throws UNKNOWN_TABLE, and an aborted file skips them.
Pinning routes one at a time cannot work.

The test's tables now live in a Memory database, whose table metadata is never written, and the
trailing drops become one DROP DATABASE, which that branch never ignores. Nothing can be replayed
at startup even if the teardown never runs.

With the stress profile and async_load_databases=0: 6 of 6 restarts refused before, 6 of 6 came up
after, 5 table metadata files before and 0 after. At the runner's own 0.2: 1 of 8 restarts failed
before and 0 of 8 after, and the test went from 3 of 8 failing to 8 of 8. 50 of 50 randomized
runs pass; .reference is unchanged.

The loader-side gap is pre-existing and tracked by #96886, per @ alexey-milovidov's ruling on #121418.


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

Version info

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

…in a Memory database

Stress test (*_asan_ubsan) failed with "Cannot start clickhouse-server" three
times in one day, twice on master, the last of them on a tree that already
contained the previous fix for this test. That fix closed the AST-fuzzer route;
this failure took a different one.

The stress runner passes ignore_drop_queries_probability=0.2 as a client option
(ci/jobs/scripts/stress/stress.py:528). Under that setting a DROP TABLE on a
table that stores data on disk is a silent no-op that reports success to the
client (src/Interpreters/InterpreterDropQuery.cpp:219-231, the early return at
:226); the branch is entered only for a table drop, since
is_drop_or_detach_database at :213 excludes DROP DATABASE. So this test's own
DROP TABLE t_scalar_constraint_user can succeed without dropping anything, and
that run's log shows exactly that, 17 ms apart:

  (query 17, line 26) DROP TABLE t_scalar_constraint_user;
  InterpreterDropQuery: Ignore DROP TABLE query for table ...t_scalar_constraint_user

The surviving table then meets the post-run restart. An asynchronous metadata
load has no query context (src/Databases/TablesLoader.cpp:80 copies the global
context and never calls makeQueryContext), so re-analysing a CHECK constraint
whose scalar subquery reads a table function reaches the unguarded
getQueryContext() in QueryAnalyzer::resolveTableFunction
(src/Analyzer/Resolve/QueryAnalyzer.cpp:5509) and throws THERE_IS_NO_QUERY. When
stress_runner.sh 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.

Four independent routes end in that same state: a renamed fuzzer clone, a fuzzed
DROP replayed as UNDROP TABLE, the ignored DROP above, and a failed ATTACH, which
keeps the metadata file while making the test's own DROP throw UNKNOWN_TABLE, as
does an aborted file (tests/clickhouse-test:4015 runs .sql with --multiquery and
no --ignore-error). The last two are reachable by no SET at all, so pinning
routes one at a time cannot work.

Hosting the tables in a Memory database removes the class instead. Such a
database never writes table metadata (src/Databases/DatabaseMemory.cpp:36-58 only
attaches in memory, there is no getMetadataPath override, and the startup loader
does not ask it for any, since supportsLoadingInTopologicalOrder is the default
false), so no leftover can be replayed at startup even when the teardown never
runs at all. The trailing drops become one DROP DATABASE, which is the one drop
that branch never ignores and which also skips same-database dependency checks,
so the HAVE_DEPENDENT_OBJECTS failure the same mechanism caused in that run goes
away too. The eight DROP TABLE IF EXISTS lines are gone because a freshly created
database is always empty, and ast_fuzzer_any_query = 0 is kept as a second belt,
as 03822_named_collection_drop_dependency_check.sh does.

Measured with the stress fuzzer profile installed and async_load_databases=0. At
ignore_drop_queries_probability=1.0, which makes the carrier fire on every draw:
before the change the restart refused to start in 6 of 6 draws (exit 210, zero
"Ready for connections", five leftover table metadata files); after it, 6 of 6
came up with no table metadata at all. At the runner's own 0.2: 1 of 8 restarts
failed before and 0 of 8 after, and the test itself went from 3 of 8 failing to 8
of 8 passing. 50 of 50 randomized runs pass and the .reference is unchanged.

The loader-side gap itself is pre-existing on master and tracked separately.
@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, and it reproduced the
forced-ignore restart on its own), plus my own cold review of the resulting file: no blockers, no
majors, the 3 nits below. No fix round was needed.

# Sev Finding Verdict Evidence / action
1 💡 No no-shared-merge-tree tag, while 03229_query_condition_cache_tables_without_uuid.sql:1-3 carries it for this exact shape (MergeTree tables inside a Memory database) AGREE, noted No effect in this repository either way: the tag is a skip gate under --cloud or --replace-replicated-with-shared (tests/clickhouse-test:3167, :3287) and no job here sets either. 01069_database_memory.sql and 01625_constraints_index_append.sql also omit it. I will add it if you prefer the 03229 convention
2 💡 Two incidental coverage deltas from hosting the tables outside the per-test database: the DETACH/ATTACH arm no longer round-trips through an on-disk metadata file, and the DBReplicated flavour no longer sends these CREATEs through the replicated-DDL queue AGREE, noted The arm still re-analyses the constraint, because the short ATTACH rebuilds the table from the stored definition. Hosting only the remote() table there would not do: the second occurrence died on a plain-table constraint whose subquery the fuzzer had rewritten to merge(...)
3 💡 The comment above DROP TABLE t_scalar_constraint_user still justifies that drop by the restart hazard, which is now handled structurally AGREE, noted Those lines are not part of this diff, so I left them alone; everything they state is still true

The two claims the fix rests on, checked at source before I read the implementation's evidence: a
Memory database writes no table metadata and the startup loader never asks it for any
(DatabaseMemory::createTable only attaches in memory, supportsLoadingInTopologicalOrder is the
default false), so no leftover of any kind can be replayed; and the ignore branch excludes a
database drop (is_drop_or_detach_database, InterpreterDropQuery.cpp:213, :219), so the one
remaining teardown statement cannot be skipped. .reference is untouched and every assertion,
serverError arm and mid-file SET is preserved.

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

Session id: cron:clickhouse-review-slot-10:20260924-202200

@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cee0c8b]

Summary: ✅


AI Review

Summary

This PR moves the fixture tables in 05234_constraint_scalar_subquery_over_distributed into a dedicated Memory database so stress-test restarts cannot replay persisted table metadata for constraint definitions that need a query context during load. I did not find an actionable correctness or test-contract regression in the current patch, and there are no new inline review comments to post.

Final Verdict

✅ No actionable findings.

@alexey-milovidov alexey-milovidov self-assigned this Sep 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 25, 2026
Merged via the queue into ClickHouse:master with commit d5d7738 Sep 25, 2026
172 of 173 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 25, 2026
BorisTyshkevich pushed a commit to BorisTyshkevich/ClickHouse that referenced this pull request Nov 15, 2026
…ne_bucket in a Memory database

Stress test (amd_msan) failed with "Cannot start clickhouse-server": the
restart could not load q_peer, "Existing table metadata in ZooKeeper
differs in buckets setting. Stored in ZooKeeper: 2, local: 1
(METADATA_MISMATCH)".

The test rewrites the Keeper metadata of q_peer to "buckets":2 to simulate
a migration by another server, then runs ALTER TABLE q_peer MODIFY SETTING
buckets = 2. In between, Keeper has 2 buckets and the table's .sql has 1,
which ATTACH refuses. The stress run's global time limit killed the client
right after the rewrite, stress.py detached (not dropped) the database,
and the restart with async_load_databases = false failed on the table.

Only q_peer has such a state: run up to every statement boundary of the
test, then detached and restarted, every other table loads. So only q_peer
moves into a Memory database, {CLICKHOUSE_DATABASE_1:Identifier}, whose
table metadata a restart never loads, as 05234 does (ClickHouse#122101). USE makes
currentDatabase() and the {database} macro of keeper_path name that
database, so the queries and the reference are unchanged; the other cases
keep running in the test database, including its Replicated variant.
DROP DATABASE is the cleanup because ignore_drop_queries_probability never
ignores it.

Related: ClickHouse#130798

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
…isk in a Memory database

The stress test stops every worker at its global time limit. Worker 0
runs the tests in the runner's default descending order, so the limit
lands in the same band of newest tests on every run; on 26.8 that band
includes 05496 (4 `Stress test` jobs in 4 days, with ClickHouse#130670 present).
The test can then stop between a `CREATE TABLE` that names a disk of an
already dropped table (`disk = '<name>'`, `storage_policy =
'__<name>'`, a wrapper of `server_<db>`) and its `DROP`.
`prepare_for_hung_check` detaches, not drops, the databases, the restart
attaches them again, the table cannot be loaded (`Unknown storage policy
__server_<db>`, `Unknown disk plain_<db>`, `The wrapped disk must have
been announced earlier`) and the server does not start.

An interruption cannot be pinned by a setting, so every table of the
test now lives in a Memory database, which keeps no table metadata on
disk: after the restart it is empty, wherever the test was stopped. That
also covers a `DROP` lost to an injected memory fault, so the
`memory_tracker_fault_probability=0` pin of the previous commit is
removed again. Same shape as ClickHouse#122101 (05234) and ClickHouse#131581 (05620).

`CREATE DATABASE ... ENGINE = Memory` stays on one line: the runner's
`--replace-log-memory-with-mergetree` (stress worker 0) rewrites
`ENGINE = Memory` to MergeTree except on a line with `CREATE DATABASE`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). 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-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