Skip to content

Feature: Enable overlay databases for server. - #86768

Closed
AlyHKafoury wants to merge 222 commits into
ClickHouse:masterfrom
AlyHKafoury:allow-creating-overlay-databases
Closed

AlyHKafoury wants to merge 222 commits into
ClickHouse:masterfrom
AlyHKafoury:allow-creating-overlay-databases

Conversation

@AlyHKafoury

@AlyHKafoury AlyHKafoury commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

Enables server-side Overlay databases. An Overlay database is a read-only facade that exposes the union of the tables of several underlying databases, resolving each table name through the listed sources in order (the first source that has the table wins). The facade has no storage of its own: CREATE TABLE through it is delegated to the first writable source database, every other DDL on the facade is rejected, while SELECT and pass-through INSERT resolve to the underlying source table. Reading, writing or creating a table through the facade requires the corresponding grant on both the facade database and the underlying source, and the facade's row policies are combined with the source's. Previously an Overlay database existed only as the implicit default database of clickhouse-local.

Closes: #52764

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Enable server-side Overlay databases: a read-only facade that exposes the union of the tables of several source databases, passes SELECT and INSERT through to the source table, and delegates CREATE TABLE to the first writable source database.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

@azat azat added the can be tested Allows running workflows for external contributors label Sep 5, 2025
@azat azat self-assigned this Sep 5, 2025
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3c776109]

Summary: ✅


AI Review

Summary

This PR enables server-side Overlay databases as read-only facades over existing source databases and carries that contract through the main query, metadata, dictionary, backup/restore, and whole-server scan paths. I did not find a remaining correctness, access-control, or compatibility issue in the current head.

Missing context / blind spots
  • ⚠️ I did not rerun the stateless or integration suites in this review pass, so confidence here comes from code inspection plus the focused coverage already added in the PR.
Final Verdict

✅ Approve

LLVM Coverage Report

Measured on commit 3c776109.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 1552/1720 (90.23%) · Uncovered code

Full report · Diff report

@AlyHKafoury
AlyHKafoury marked this pull request as ready for review September 7, 2025 13:04
@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 7, 2025
@AlyHKafoury

Copy link
Copy Markdown
Contributor Author

@azat I believe this is ready for initial review, I don't know why the rest of the CI is not running

@ClickHouse ClickHouse deleted a comment Sep 8, 2025

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@AlyHKafoury

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov this test is failing with random error messages that doesn't happen in other runs or locally can you give me any pointers on why this might be failing ? https://github.com/ClickHouse/ClickHouse/actions/runs/17553376388/job/49853979804?pr=86768

@AlyHKafoury

Copy link
Copy Markdown
Contributor Author

@azat @alexey-milovidov I believe this is ready for review

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 53e64aa71cff..4be5258ebbf6: the Major of the 2026-09-20 AI Review verdict, with a control-proved regression test, plus a whitespace repair and a hand re-sync of the private mirror.

7973d7c1a805 — CREATE TABLE through a facade whose earlier source is unresolved. tryGetTableCreationDatabase picked the first writable database of resolveDatabases, which deliberately drops a source that is not registered right now — the lazy resolution that lets a facade come up before its sources during loadMetadata, ATTACH, or a restore. Table placement was therefore time-dependent: with Overlay('db_a', 'db_b') and db_a temporarily absent, CREATE TABLE ov.t created db_b.t, and the facade-wide isTableExist check of InterpreterCreateQuery, walking the same shortened list, equally missed an existing db_a.t; once db_a returned, the facade order reverted and the new table was owned by the wrong database or shadowed. The creation path now walks the configured source names in order and fails closed with UNKNOWN_DATABASE while a source that precedes the creation target is unresolved. The message names only the facade, as every other diagnostic raised through it does; the source name goes to the server log. A source that follows the creation target cannot change the placement, so it is not an obstacle, and reads are unchanged. Documented in both the Documentation block of DatabaseOverlay.cpp and overlay.mdx; autogenerate_docs.py --check --only overlay is ok. Test 05235_overlay_database_create_table_unresolved_source.

4be5258ebbf6 restores the indentation of the try before tryGetTable in StorageSystemIcebergHistory, lost in the conflict resolution of the master merge 75b25761d96e. Whitespace only.

Verification. ninja clickhouse exit 0. Against a local server from this build the overlay_database selector is 48/52; the 4 remaining failures are environmental in this worktree only (no graphite_rollup config, no ZooKeeper, /var/lib/clickhouse/user_files not writable). On a control build with DatabaseOverlay.cpp reverted, the new test fails exactly as the finding describes — both t_second and t_owned are created in db_b — and passes with the fix.

CH Inc sync. The sync PR was left at 9b80bcd5f498 and conflicting with the private master, with the bot reporting that manual intervention is needed. Re-synced by hand: the private master merge had the same StorageSystemIcebergHistory.cpp conflict as the public one and was resolved to the same union, then the public head was merged in. git diff --numstat of the sync branch against the private master now matches the public diff for all 176 files except the known one-line include deduplication in InterpreterCreateQuery.cpp, and there is no contrib drift. The sync PR is MERGEABLE again and its CI is running.

The only CI failure on 53e64aa71cff was that CH Inc sync; the other 128 jobs passed. All 144 review threads are resolved.

Comment thread src/Databases/DatabaseOverlay.cpp Resolved
alexey-milovidov and others added 3 commits September 21, 2026 13:24
…ource on the create path

Two findings of the 2026-09-21 AI review of the `Overlay` database facade.

The rejection of an explicit `ATTACH DATABASE ... ENGINE = Overlay(...)` layered
over another read-only facade was keyed on `!args.internal`. An internal query is
not necessarily the server's own metadata replay: wrappers such as `PARALLEL WITH`
execute user statements as internal ones, so
`PARALLEL WITH ATTACH DATABASE db_top ENGINE = Overlay('db_mid')` skipped the guard
and persisted a facade whose source `resolveDatabases` has to drop on every lookup.
The guard now keys on the loader's own replay flag, `args.is_metadata_replay`,
exactly as `DatabaseFilesystem` already does; startup replay still must not refuse
a previously-written definition.

`tryGetTableCreationDatabase` failed closed for a source that is currently
unresolved, but still skipped a source that resolves to a nested read-only
`Overlay`. That shape is reachable from metadata written before the checks above
existed, and the documented repair -- re-creating that source as an ordinary
database -- puts the source back into the facade order, so a table created past it
would then be owned by the wrong source, or shadowed by a table of the same name in
the source the create walked past. It is now rejected with `BAD_ARGUMENTS` for the
same reason as an unresolved source, naming only the facade.

Tests: `05236_overlay_database_parallel_with_attach_nested_rejected` for the first
finding, and `test_database_overlay` for the second -- the nested state is only
reachable through a metadata replay, so it needs a server restart.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ests runnable

Measured against a control binary built from the previous head: the explicit
`PARALLEL WITH ATTACH DATABASE ... ENGINE = Overlay(...)` form was *already*
refused before the previous commit, because `PARALLEL WITH` marks its
sub-statements `user_initiated` and `executeQuery` therefore does not pass
`internal` on to `InterpreterCreateQuery` (`setInternal(internal && !flags.user_initiated)`,
added in `031704da17b3`). Keying the guard on `args.is_metadata_replay` is kept --
it states the intent directly instead of depending on that propagation, exactly as
`DatabaseFilesystem` already does -- but the comment no longer claims the form
slipped through, and the test now says what it pins.

Also: `PARALLEL WITH` refuses a branch that has output, so the single-statement
branches of the new test use a `DROP DATABASE IF EXISTS` of an absent database
rather than `SELECT 1`, and the integration test is `black`-formatted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Pushed 4be5258ebbf6..42ba94616bb7: both Majors of the 2026-09-21 AI Review verdict, one of them with a correction to its premise, plus a master merge.

b63a586aa52d — a nested source on the CREATE TABLE path. tryGetTableCreationDatabase failed closed for a source that is currently unresolved but still skipped a preceding source that resolves to a nested read-only Overlay. That shape is only reachable from metadata written before the nesting checks existed, and the documented repair — re-creating that source as an ordinary database — puts it back into the facade order, so a table created past it would afterwards be owned by the wrong source, or shadowed by a table of the same name in the source the create walked past. It is now rejected with BAD_ARGUMENTS, naming only the facade.

The regression is tests/integration/test_database_overlay, because the state is not reachable from SQL — every CREATE / ATTACH / SECONDARY_CREATE path refuses the nesting from both sides, so it takes a metadata replay and a restart. Control-proved: on a binary built from the previous head CREATE TABLE db_top.t_second succeeds and the table lands in the later source; with the fix it is refused.

The replay-only ATTACH guard. The guard now keys on args.is_metadata_replay instead of !args.internal, as the finding asks, and 05236_overlay_database_parallel_with_attach_nested_rejected covers the PARALLEL WITH ATTACH DATABASE ... ENGINE = Overlay(...) shape. The premise, however, is refuted by measurement: against a control binary from the previous head that statement was already refused, because InterpreterParallelWithQuery marks its sub-statements user_initiated and executeQuery therefore does not pass internal on to the create interpreter (setInternal(internal && !flags.user_initiated), from 031704da17b3). The change is kept because it states the intent directly instead of depending on that propagation, as DatabaseFilesystem already does here; startup replay stays exempt either way, since it runs with FORCE_ATTACH. 42ba94616bb7 corrects the comment and the test's description accordingly.

Verification. ninja clickhouse exit 0 on the merged tree. Against a local server from that build the overlay_database selector is 49/53; the 4 remaining failures are environmental in this worktree only (no graphite_rollup config, no ZooKeeper, /var/lib/clickhouse/user_files not writable — the tests use the default path rather than the one this server is configured with). The integration test passes with pytest against a real container. autogenerate_docs.py --check --only overlay is ok, and various_checks.sh is clean.

master merge. 449 behind with a merge base from 2026-09-20 16:57Z, no conflicts, no test-number collisions. It also re-draws the performance comparison, whose single failure I believe to be noise — see the next comment.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 On the only CI failure of 4be5258ebbf6, Performance Comparison (arm_release, master_head, 2/6): lazy_final_early_exit_limit #0, client_time 20.6 ms → 23.8 ms (+15.7%), reported as a confirmed regression. I believe it is noise, on three grounds.

The query cannot reach this change. It is SELECT k, payload FROM lazy_final_limit FINAL WHERE v = 7 LIMIT 100 over a ReplacingMergeTree, with no Overlay database anywhere. Everything this PR adds outside the Overlay engine itself runs once per table at analysis time — getSourceTableIdForReadonlyFacade in PlannerJoinTree / InterpreterSelectQuery, and the row-policy combination next to it — and each of those returns immediately for a table whose database is not a facade. Nothing is added per row, per granule, or per part.

Both numbers sit inside the query's own noise band. On that exact shard over the last 21 days (2694 runs, play.clickhouse.com checks):

p05 p50 p95
old 20 ms 22 ms 24 ms
new 20 ms 22 ms 24 ms

20.6 ms and 23.8 ms are the bottom and the top of a band the query occupies on unmodified master as well — and at 22 ms the measurement grid is ~4.5% per millisecond.

A swing this size is ordinary for this query. Across those same 2694 runs, |new − old| / old exceeds 15.7% in 216 (8.0%), of which 113 (4.2%) are in the slower direction, with a maximum of 30%. With ~1200 queries per shard, a draw like this one is expected on a large fraction of runs.

The job was also labelled disk-almost-full.

The branch has since been merged with master and pushed, so the comparison is re-drawn on 42ba94616bb7. Report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/86768/4be5258ebbf61cceb655fbc660cb3a4256693617/pr/performance_comparison_arm_release_master_head_2_6/report.html

alexey-milovidov and others added 2 commits September 22, 2026 04:29
…ame in `system.dictionaries`

A dictionary created in a source database of a read-only `Overlay` facade is
reachable through the facade name by the point lookups (`SHOW CREATE DICTIONARY`,
`EXISTS DICTIONARY`, `SYSTEM RELOAD DICTIONARY`), but `SHOW DICTIONARIES FROM ov`
is rewritten to `system.dictionaries WHERE database = 'ov'`, and
`StorageSystemDictionaries` emitted rows under the owning source name only, so
even a caller granted on both the facade and the source never saw `ov.d` in the
listing. The listing now synthesizes a row under the facade name for every
read-only facade that resolves the dictionary name to that very source, under
the same fail-closed dual-grant rule as the other facade metadata readers:
`SHOW DICTIONARIES` must be granted on both the facade name and the source name,
the resolution never loads the source object, and a name that an earlier source
shadows (with a table or a dictionary of its own) is not advertised through the
facade, because through the facade that name denotes the earlier source's object.

`DatabaseOverlay::tryGetVisibleSourceDatabaseNameNoLoad` is the resolving form of
`isSourceTableVisibleNoLoad` (which now delegates to it): it returns the source
database the name resolves to when both grants hold, and an empty string otherwise.

Test `05237_overlay_database_show_dictionaries_facade` covers the default user
(the shadowed name is listed for its source only and agrees with `EXISTS
DICTIONARY` / `SHOW CREATE DICTIONARY` on the facade name), a facade-only grant,
a source-only grant, and the dual grant.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

alexey-milovidov commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

🕵 Pushed 42ba94616bb7..9dec09b69ee1: the Major of the 2026-09-21 AI Review verdict plus a master merge.

9dec09b69ee1 — dictionaries are listed under the facade name. A dictionary created in a source database of a read-only Overlay facade was reachable through the facade by the point lookups (SHOW CREATE DICTIONARY ov.d, EXISTS DICTIONARY ov.d), but SHOW DICTIONARIES FROM ov is a query over system.dictionaries WHERE database = 'ov', and StorageSystemDictionaries emitted rows under the owning source name only, so even a dual-granted caller never saw ov.d in the listing. The listing now synthesizes a row under the facade name for every read-only facade that resolves the dictionary name to that very source, under the same fail-closed dual-grant rule as the other facade metadata readers: SHOW DICTIONARIES on both the facade name and the source name, no load of the source object, and a name that an earlier source shadows is not advertised through the facade (there ov.<name> denotes the earlier source's object, and SHOW CREATE DICTIONARY on it already says is not a DICTIONARY). The resolving helper is DatabaseOverlay::tryGetVisibleSourceDatabaseNameNoLoad; isSourceTableVisibleNoLoad delegates to it. Test 05237_overlay_database_show_dictionaries_facade covers the default user with a shadowed name, a facade-only grant, a source-only grant and the dual grant, and the docs gained the corresponding sentence in the metadata-visibility section.

Verification. ninja clickhouse exit 0 on the merged tree. Against a local server from that build, the new test passes, the eight existing dictionary-related overlay_database tests pass, and the full overlay_database selector plus every stateless test that reads system.dictionaries is 96/102; the six failures are environmental in this worktree only (no test_shard_localhost / test_cluster_two_shards clusters, no graphite_rollup, no ZooKeeper, a relative user_files_path that the dictionary FILE source rejects); none of them touches system.dictionaries rows of a facade, and the first four failed identically in the previous local passes on this branch.

CI. Public CI on 42ba94616bb7 was green apart from CH Inc sync. The private mirror run failed on every meta in keeper shard with Logical error: Background compaction is not initialized. This is a bug. (STID: 2737-36cb) and its Server liveness check failed — that is clickhouse-private#76481, fleet-wide on the private side, with the fix clickhouse-private#76501 open; nothing in this PR touches background compaction. The remaining private reds are the known timeouts 03012_shared_merge_tree_alter_stress (clickhouse-private#58397) and 04238_alter_rename_column_merge_race (clickhouse-private#63469).

Merged origin/master (322 commits, conflict-free) so the new run is measured against a current base.

… facade in `dictGet` and `dictionary`

`system.dictionaries` and `SHOW DICTIONARIES FROM ov` list a source dictionary under the facade name, but the
consumers that take the name as a string could not use it: `ExternalDictionariesLoader::resolveDictionaryNameFromDatabaseCatalog`
saw the facade (UUID `Nil`) as the owning database and kept the written string `ov.d`, which the loader does not know
(the dictionary is registered under its source key only), so `dictGet('ov.d', ...)`, `dictionary('ov.d')` and the
current-database form failed with `Dictionary (...) not found`.

The resolver now follows the storage the facade returns to its registered key (`StorageID::getInternalDictionaryName`:
the UUID for an `Atomic` source, `database.name` otherwise). The consumers follow the facade's dual-grant contract through
the new `DatabaseOverlay::checkDictionaryAccessIfFacade`: `dictGet` is required on both the facade name and the source
dictionary, checked fail-closed before the source dictionary is loaded, and the denial names only the facade. It is
called from `FunctionDictHelper::getDictionary`, `TableFunctionDictionary::getActualTableStructure` and
`StorageDictionary::read` for a custom name (the `dictionary` table function and the `Dictionary` table engine).
A name that an earlier source shadows with an object of its own still resolves to that object and stays unresolvable
as a dictionary, consistent with the listing.

Test `05238_overlay_database_dictget_through_facade` covers every consumer for the default user, the shadowed name,
and the facade-only / source-only / both-grants users.

AI review: ClickHouse#86768 (comment)
CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=86768&sha=9dec09b69ee1611992e317207a9e454c6c3141c0&name_0=PR

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status 2026-09-22 (pass on head 9dec09b69ee1, pushed 7e4f3f187a9d):

…lay-databases

Conflicts: `QueryAnalyzer.cpp`, `InterpreterSelectQuery.cpp`, `PlannerJoinTree.cpp` — master (ClickHouse#118668) moved the
row-policy resolution into the shared `getRowPolicyFilterForStorage` / `getEffectiveRowPolicyFilter` helpers in
`Storages/getEffectiveRowPolicyFilter.h`, replacing the per-call-site code where this branch combined the policies of
the `Overlay` facade name with the source's. Resolved by adding `as_written_id` overloads of the two shared helpers
that combine the other name's policies when the written id resolves through a read-only facade (plain source table:
the facade's policies; parameterized view: the carried source view's policies), and by switching the three call sites
to them; the branch's local planner copy of `getEffectiveRowPolicyFilter` is dropped in favour of the shared one.
`DatabaseOverlay::getSourceTableIdForReadonlyFacade` gained an `IStorage const &` overload for the helper.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@groeneai

ghost commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Checked both on 9dec09b69ee1. The msan one is covered by #119814. The perf one is not covered by #121090 alone: it needs #121189 as well.

Stress test (amd_msan), pushed bucket 2 twice: #119814 covers it, no different fix needed. The abort is STID 3994-4c1d at MergingAggregatedMemoryEfficientTransform.cpp:63, pushData under tryPushTwoLevelData() from prepare() (job), the same signature I measured on this branch last week: 10/10 red on 262fbe8c874b and on #119814's own master base b3146411, 0/20 green with #119814 applied, with buckets 1, 2, 3 and 5 all appearing in the red arm, so bucket 2 sits inside what was tested. 3df00505 (#116446) is an ancestor of 9dec09b6, so the rule-based guard is already in and the Cascades path is the one left open. Supporting: #119814's own CI has 150 stress rows across 3 heads with no occurrence of the signature.

Performance Comparison (arm_release, master_head, 1/6), order_by_read_in_order #1: #121090 alone leaves this shard red.

That shard obtained no learned per-query thresholds on this run: WARNING: Failed to fetch historical thresholds, will proceed without them at 08:21:11Z (job). historical-thresholds.tsv is empty after that, so ceil(greatest(0.15, historical_thresholds.max_diff, test_thresholds.report_threshold), 2) collapses to the 0.15 floor for every query in the shard, and +39.1% crosses it. CIDB records order_by_read_in_order #1 as slower (the only such row in the shard), and the gate line is 5 too long, 1 slower; 1 confirmed regression(s) on the performance dashboard. For scale, that shard-side slower verdict on this one query fired across 274 distinct PRs and 106 master rows in the last 7 days.

#121090 keeps a dashboard row only when the shard's own report also published the query as slower. Here it did, so the confirmed_regression row survives the new filter and the status is still FAIL; 1 slower is under SLOWER_QUERIES_FAIL_THRESHOLD = 10, so the count itself is not what fails the check. #121189 is the half that removes the cause: it writes the missing-thresholds marker on exactly this fetch failure, so the shard judges nothing instead of judging against the floors, and reports SKIPPED. The reverse also holds, #121189 without #121090 stays red, because the dashboard gate judges every query the shard measured regardless of the shard's own verdict. So both halves are needed for this failure, not #121090 by itself.

Both are open and unmerged. I will post here when they land.

@alexey-milovidov

ghost commented Sep 22, 2026

Copy link
Copy Markdown
Member

🕵 Follow-up 2026-09-22: the PR had become CONFLICTING against master shortly after the previous push (GitHub does not start pull_request workflows for a conflicting PR, which is why 7e4f3f187a9d had no CI run). Merged origin/master (3c973e96156d) in 3c77610940ef.

Conflicts came from #118668, which moved row-policy resolution into the shared getRowPolicyFilterForStorage / getEffectiveRowPolicyFilter helpers. Resolution: the shared helpers gained as_written_id overloads that combine the other name's policies when the written id resolves through a read-only Overlay facade (plain source table: the facade's policies; parameterized view: the carried source view's policies), and QueryAnalyzer, InterpreterSelectQuery and PlannerJoinTree now call them instead of the branch's per-call-site combining code; the branch's local planner copy of getEffectiveRowPolicyFilter is gone.

Verified locally: incremental ninja clickhouse clean; the overlay row-policy tests (03611_overlay_database_row_policies, 04614_overlay_database_view_inline_row_policy, 04661_overlay_database_parameterized_view_permissions), master's new 05076_row_policy_underlying_storages / 05138_merge_child_row_policy_trivial_count, and the dictionary facade tests (05233, 05234, 05237, 05238, 04617, 04829, 05210) pass.

@alexey-milovidov

ghost commented Sep 22, 2026

Copy link
Copy Markdown
Member

🕵 Status 2026-09-22 (pass on head 3c77610940ef, nothing to push on the public side):

@alexey-milovidov

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Member

🕵 Status 2026-09-23 (head 3c77610940ef, nothing to push): public CI is green, 0 unresolved review threads. The only red is CH Inc sync = tests failed (1 new, 2 known) on the private sync PR, all outside the Overlay code paths: 05227_mutation_partition_pruning_alias_nondeterministic (tsan, result differs for a non-deterministic alias mutation), Stress test (arm_asan_ubsan, SharedCatalog) smoke check killed by injected Keeper fault Fault injected (during table creation) in 00234_disjunctive_equality_chains_optimization, and 600 s timeouts of 04669_creating_set_partitions_independently / 04798_mutation_row_exists_from_patch_part on msan. Re-ran the failed private jobs.

@groeneai

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

The Stress test (arm_tsan) hung check you asked me to investigate here on 2026-08-08 is covered by an open PR of mine, and I had never posted the link on this thread, so here it is: #119124.

Re-read from the artifact, since only the last 32 KiB of hung_check.log reaches test_context_raw and this sink sits at byte 14462 of 352784. One hung row on 399ef4e9: query b4506603, elapsed 1379.70, is_cancelled 1, read_rows 0, against max_execution_time 10, and its whole sample is one walk:

SharedMutex::lock_shared <- SerializationObjectPool::getOrCreate <- ISerialization::pooled
  <- SerializationArray::create <- SerializationArray::SubcolumnCreator::create
  <- ISerialization::createFromPath <- IDataType::forEachSubcolumn
  <- Array/Map/Named/Tuple enumerateStreams, 33 frames

The caller frame is below the printed depth, but it is Merge structure inference rather than the hint path. The same artifact carries an unrelated exception trace showing this query reaching merge() through QueryAnalyzer::resolveTableFunction -> Context::executeTableFunction -> ITableFunction::execute -> TableFunctionMerge::executeImpl -> StorageMerge::StorageMerge, whose constructor infers the columns when none are cached (StorageMerge.cpp:268); TableFunctionExecute is counted at ITableFunction.cpp:69, just before that call, and the row has it at 1 with read_rows 0. TypoCorrection, NamePrompter and getHints appear 0 times in the whole 352 KB.

#119124 gives IDataType::forEachSubcolumn a cancellation budget and charges it in that inference per source table and per column, so KILL QUERY and max_execution_time are observed inside one column's substream tree instead of only between enumerations. It was opened for the same shape on #115378: four merge(REGEXP(...), ...) rows, 620 to 1944 s, all is_cancelled 1, read_rows 0, all sampling that same chain.

The link I gave here on 2026-08-09, #113996, is closed: @ PedroTadim reverted that mechanism on 2026-08-12 (#112203) as the wrong shape, and #119124 is the budget shape instead. The hint half of the same family, NamePrompter::getHints scoring candidates without observing cancellation, is #116356. Neither has a human review yet.

Separately, on the private sync reds: 04798_mutation_row_exists_from_patch_part is mine. It has 13,872 public runs and 0 failures in 30 days, and on amd_msan its p90 is 104 s and its maximum 126.6 s against the 600 s limit. It timed out together with 04669_creating_set_partitions_independently, which shares nothing with it, so that shard stalled rather than either test being slow.

@alexey-milovidov

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Member

🕵 Status 2026-09-23 (head 3c77610940ef, nothing to push): all 158 checks pass (including CH Inc sync after the rerun of the failed private jobs), 0 unresolved review threads, MERGEABLE, AI review ✅ Approve.

@groeneai, thanks: noted that the 2026-08-08 Stress test (arm_tsan) hung check (merge() structure inference stuck in IDataType::forEachSubcolumn) is covered by #119124, superseding the reverted #113996, and that the 04798 / 04669 msan timeouts were a stalled shard, not either test. None of this touches the Overlay code paths, and it does not block this head.

@groeneai

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

The Fast test abort you asked me to investigate here on 2026-08-16 is fixed on master, so there is no new PR from me. Not by #115061, which I linked on 2026-08-17 and which was closed unmerged the next day.

Owning diff: #112984, merged 2026-08-29; the change is in 6455c44a3fc1. It retires the leak I described in that earlier comment. Shell._check_timeout used to be a bare time.sleep(timeout) followed by an unconditional os.killpg, with nothing cancelling the thread when the command returned early, which is how a 300 s watchdog armed for a 21.8 s git submodule update came to signal recycled process group 66 and kill clickhouse-test at test 96/13849. It now waits on a finished event that is set in a finally around the reader joins, so it cannot signal a group it no longer owns. The 300 s arming site in fast_test.py is still there, it is just no longer able to outlive its command.

Fix-presence check in CIDB, keyed on Fast test jobs that report Server died with a Failed: 0 summary and an early abort: 6 of the 7 weeks from 2026-07-06 to 2026-08-23 had occurrences, 2 to 33 jobs each, with 24 distinct PRs in the week of 2026-07-20 alone. The last one is 2026-08-23 20:30:23 on this PR, and there have been none in the 30 days since. Server died rows are still ingested over that window (3 Fast test jobs on 2026-09-22, each with real test failures), so the query still sees the shape.

This is separate from the DatabaseOverlay::getUUID re-entrancy you root-caused here on 2026-09-06, which is PR-local and produces the same visible tail.

@alexey-milovidov

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Member

🕵 @groeneai, thanks: noted that the 2026-08-16 Fast test abort (Shell._check_timeout signalling a recycled process group) is fixed on master by #112984 (6455c44a3fc1), with no occurrences since 2026-08-23. The PR-local DatabaseOverlay::getUUID catalog deadlock that caused the same visible tail was fixed here in 4e6c0f7bbda5. Head 3c77610940ef is unchanged: all 158 checks pass, 0 unresolved review threads, MERGEABLE. Nothing to push.

@alexey-milovidov

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Member

Now the biggest question is why it is 8000 lines of code and tests.
This was intended as a simple feature for some rare use-cases. The complexity is certainly not worth it.

I think we need to "reset" the implementation. If we resubmit, I will make sure to credit the original author.

@alexey-milovidov

ghost commented Sep 23, 2026

Copy link
Copy Markdown
Member

An idea: what if we reuse the same StorageTableProxy mechanism as we do for lazy databases?

@groeneai

ghost commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Neither #121189 nor #121090 will land: @ fm4v closed both unmerged on 2026-09-23 in favor of #121847, which merged as da7ece5f93aa. It removes the cause of the perf red above at the source rather than downstream of it: the empty historical-thresholds.tsv came from a 10 s CIDB timeout on a query that takes 8 to 10 s, which the PR's own comment says "lost the thresholds of about half of the runs", so that shard now judges order_by_read_in_order #1 against its learned threshold instead of the 0.15 floor.

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-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. manual approve Manual approve required to run CI pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow creating Overlay databases

5 participants