Repository navigation
Add lazy_load_tables database setting for deferred table loading - #96283
Conversation
|
Workflow [PR], commit [65019fe] Summary: ❌
|
Introduce a new Bool database setting `lazy_load_tables`. When enabled, tables are not loaded during database startup. Instead, a lightweight `StorageTableProxy` is created and the real table is materialized on first access. Views, dictionaries, materialized views, and table functions are excluded from lazy loading.
7a21800 to
cf03299
Compare
The flaky check runs tests 50 times. Hardcoded database name
`test_lazy_load` caused `DATABASE_ALREADY_EXISTS` errors on
concurrent reruns. Switch to `{CLICKHOUSE_DATABASE_1:Identifier}`
for a unique name per run.
Add `USE` after each DETACH/ATTACH cycle and replace parameterized database name with `currentDatabase` in `system.tables` WHERE clauses, as required by the CI style check.
There was a problem hiding this comment.
Pull request overview
Adds a new database-level lazy_load_tables setting to defer loading on-disk tables at database startup by attaching a lightweight proxy storage and materializing the real engine on first access.
Changes:
- Introduces
StorageTableProxyto lazily materialize the underlying storage on first read/write/drop. - Extends
DatabaseOrdinaryto attachStorageTableProxyduring metadata loading whenlazy_load_tablesis enabled. - Adds a stateless query test covering proxy visibility in
system.tables, first access behavior, andDROPon an unloaded proxy.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/03823_lazy_load_tables.sql | Adds integration test for lazy table loading via detach/attach cycle and first access. |
| tests/queries/0_stateless/03823_lazy_load_tables.reference | Expected outputs for the new lazy-load test. |
| src/Storages/StorageTableProxy.h | New proxy storage that loads the real table storage on-demand and delegates operations. |
| src/Databases/DatabaseOrdinary.h | Declares helpers to decide and attach tables lazily. |
| src/Databases/DatabaseOrdinary.cpp | Implements lazy attach path and eligibility checks for lazy loading. |
| src/Databases/DatabaseMetadataDiskSettings.h | Extends metadata disk settings to support Bool settings. |
| src/Databases/DatabaseMetadataDiskSettings.cpp | Adds lazy_load_tables setting and ensures applyChanges() is called when disk isn’t specified. |
Comments suppressed due to low confidence (1)
src/Databases/DatabaseMetadataDiskSettings.cpp:1
- This introduces a new user-facing setting (
lazy_load_tables) but the PR metadata indicates documentation is not yet written. Please add user docs for the new database setting (scope, limitations/exclusions like views/dictionaries, and the observable behavior insystem.tables) to avoid discoverability/support issues.
#include <Databases/DatabaseMetadataDiskSettings.h>
|
Thanks for the review! Addressed in c2799e8:
|
- Harden `StorageTableProxy::drop` and `checkTableCanBeDropped` - Capture `global_context` instead of `local_context` in lazy-load lambda - Make `renameInMemory` explicit instead of relying on base class - Expand `lazy_load_tables` documentation - Fix RENAME test to avoid dependency conflict
`StorageProxy::renameInMemory` calls `getNested()` which triggers lazy loading. We intentionally call `IStorage::renameInMemory` directly to update the `StorageID` without loading the nested table.
tiandiwonder
left a comment
There was a problem hiding this comment.
Looks good! @alexey-milovidov
|
Hi, could someone please this PR? |
|
Would it help with #87707 ? |
|
Hi, my PR #96283 (lazy_load_tables) won't help here. It's implemented in |
|
We already have |
There was a problem hiding this comment.
Also, what's the difference from
ClickHouse/src/Storages/StorageProxy.h
Line 11 in 40f760c
|
@tavplubix please read the description in #94039 and watch the presentation https://presentations.clickhouse.com/2026-release-26.2/ |
…ETACH catch-22 Deliverable 3 of the stuck-table-load fix. A CAS-free description of the generic ClickHouse problem: a table whose async load job fails is permanently stuck until restart, and DETACH cannot recover it because table resolution (DatabaseCatalog/DatabasesCommon waitTableStarted) waits on the failed load job before reaching the state-erasing detach path. References lazy_load_tables (ClickHouse#96283) and related issues ClickHouse#88934/ClickHouse#67521. Draft only; not filed.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
lazy_load_tablesdatabase setting. When enabled, tables are not loaded during database startup — a lightweightStorageTableProxyis created instead and the real table engine is materialized on first access.Documentation entry for user-facing changes
Motivation: Large databases with many tables can have slow startup times because every table is loaded eagerly. The
lazy_load_tablessetting allows deferring table loading until the table is actually accessed, reducing startup time and memory usage for databases where only a subset of tables are actively queried.Parameters:
lazy_load_tables(Bool, defaultfalse) — Database-level setting. When set to1/true, tables are replaced with a lightweightStorageTableProxyduring database startup. The real storage engine is created and started on first read/write access.Scope: Works with
Atomic,Ordinary, and similar on-disk database engines. Views, dictionaries, materialized views, and table functions are excluded from lazy loading (they load normally).Example use:
Closes #94039
Version info
26.2.1.950