Repository navigation
Resolve lazily loaded table proxies before casting to an engine type - #121332
Conversation
…, enforced by a style check
|
Workflow [PR], commit [82dd687] Summary: ✅
AI ReviewSummaryThis PR replaces raw engine casts on catalog storages with proxy-aware Missing context / blind spots
Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 82dd687.
Changed lines: Changed C/C++ lines covered: 547/633 (86.41%) · Uncovered code |
…alog, and in the insert and projection paths
…r URL proxies expose their delegate
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units76 translation units recompiled, 817 s compile time in total, 76 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…rdless of lazy_load_tables
…n runs on, the type test still looks through every proxy
…ry is loaded eagerly
…e-check # Conflicts: # src/Interpreters/ActionsVisitor.cpp # src/Interpreters/ExpressionAnalyzer.cpp
bbabdd8 to
0ecb8c0
Compare
| void DatabaseOrdinary::restoreMetadataAfterConvertingToReplicated(StoragePtr table, const QualifiedTableName & name) | ||
| { | ||
| auto * rmt = table->as<StorageReplicatedMergeTree>(); | ||
| auto rmt = castStorage<StorageReplicatedMergeTree>(table, DeferredTable::Skip); |
There was a problem hiding this comment.
startupTableAsync calls this on the object returned by tryGetTableNoWait, which is still StorageTableProxy for a lazy ReplicatedMergeTree created via convert_to_replicated. Because StorageTableProxy::startup is a no-op, DeferredTable::Skip makes this return nullptr and we exit before removing the convert_to_replicated flag or calling restoreMetadataInZooKeeper. The first user access later loads the table, but this helper is never re-run, so the table stays in the post-conversion readonly state until someone does a manual SYSTEM RESTORE REPLICA.
This needs to force materialization when the flag is present (or otherwise run the repair from the lazy-load path), and then use the resolved storage for the policy lookup below instead of table->getStoragePolicy(), because StorageTableProxy::getStoragePolicy() is nullptr.
| ColumnsDescription TableFunctionMergeTreeProjection::getActualTableStructure(ContextPtr context, bool /*is_insert_query*/) const | ||
| { | ||
| auto source_table = DatabaseCatalog::instance().getTable(source_table_id, context); | ||
| auto source_table = resolveStorageProxyLoading(DatabaseCatalog::instance().getTable(source_table_id, context)); |
There was a problem hiding this comment.
This still resolves and inspects source_table_id before any source-table privilege check. ITableFunction::getActualTableStructureWithAccess only calls checkSourceAccess, but for mergeTreeProjection that is a no-op because getStorageEngineName() returns "". As a result, DESCRIBE TABLE mergeTreeProjection(db, tbl, proj) / CREATE TABLE ... AS can reveal whether a hidden table has a projection and what columns it exposes even when the caller has no grants on db.tbl.
Please add an explicit access check before the catalog lookup, similar to TableFunctionLoop: SHOW_COLUMNS for structure resolution here, and SELECT on the source table before constructing the executable storage in executeImpl.
| ColumnsDescription TableFunctionMergeTreeIndex::getActualTableStructure(ContextPtr context, bool /*is_insert_query*/) const | ||
| { | ||
| auto source_table = DatabaseCatalog::instance().getTable(source_table_id, context); | ||
| auto source_table = resolveStorageProxyLoading(DatabaseCatalog::instance().getTable(source_table_id, context)); |
There was a problem hiding this comment.
Same issue here: getActualTableStructureWithAccess reaches this code with no source-table grant check because mergeTreeIndex does not override checkSourceAccess and its getStorageEngineName() is empty. A caller can therefore DESCRIBE TABLE mergeTreeIndex(db, hidden_tbl, ...) and learn the table's primary-key columns / mark-stream layout without SHOW_COLUMNS or SELECT on the source table.
Please gate this entrypoint before DatabaseCatalog::getTable, mirroring TableFunctionLoop / mergeTreeTextIndex: SHOW_COLUMNS for getActualTableStructure, and SELECT when building the executable storage.
|
📊 Cloud Performance Report
No regressions were flagged. This PR replaces direct storage casts with castStorage so that lazily loaded tables resolve correctly, mostly in DDL, INSERT, SYSTEM and catalog paths, and adds a style check for it. The only flagged queries are TPC-H Q1 (-18.5%) and Q7 (-16.0%), both stayed not_sure and neither is a confirmed result. Master's own timings for both queries became unstable around 2026-10-02, and the diff does not touch scan, aggregation or join execution, so neither improvement can be credited to this change. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
…e-check # Conflicts: # src/Interpreters/ActionsVisitor.cpp # src/Interpreters/MutationsInterpreter.cpp
| const OptionalVectorSearchParameters & vector_search_parameters_) | ||
| : StorageWithCommonVirtualColumns(table_id_) | ||
| , source_table(source_table_) | ||
| , source_table(resolveStorageProxyLoading(source_table_)) |
There was a problem hiding this comment.
StorageMergeTreeAnalyzeIndexes::readImpl is still the first place that checks SELECT on the source table, but this constructor now resolves the lazy source, verifies that it is MergeTree, and enumerates its parts and settings before that check runs. That means mergeTreeAnalyzeIndexes(...) and mergeTreeAnalyzeIndexesUUID(...) can still disclose an inaccessible table through constructor-time UNKNOWN_TABLE / BAD_ARGUMENTS, and for lazy tables this change now goes further by materializing the table and its part list before any privilege check.
Please move the source resolution and part enumeration behind an access check, or add an equivalent early source-table check in executeImpl for both the name and UUID entrypoints. mergeTreeCodecBlockCounts in the same family now uses that shape.
|
This also fixes #122297 (hypothetical index and projection DDL, and |
|
@evillique can you add the test cases from #122297 here? |
… under the database lock
…nd test hypothetical objects on lazily loaded tables
Cherry pick #121332 to 26.9: Resolve lazily loaded table proxies before casting to an engine type
…casting to an engine type
Cherry pick #121332 to 26.3: Resolve lazily loaded table proxies before casting to an engine type
…casting to an engine type
Cherry pick #121332 to 26.7: Resolve lazily loaded table proxies before casting to an engine type
…casting to an engine type
Cherry pick #121332 to 26.8: Resolve lazily loaded table proxies before casting to an engine type
…casting to an engine type
Backport #121332 to 26.9: Resolve lazily loaded table proxies before casting to an engine type
Backport #121332 to 26.7: Resolve lazily loaded table proxies before casting to an engine type
Backport #121332 to 26.8: Resolve lazily loaded table proxies before casting to an engine type
Backport #121332 to 26.3: Resolve lazily loaded table proxies before casting to an engine type
…subcolumns Conflicts: - StorageMaterializedView.cpp, StorageMerge.cpp: master removed the legacy `order_optimizer` read-in-order path (ClickHouse#121390); kept the access-check changes. - TableFunctionMergeTreeIndex.cpp, TableFunctionMergeTreeTextIndex.cpp: master wraps `getTable` in `resolveStorageProxyLoading` (ClickHouse#121332); kept the `SHOW_TABLES` check before the lookup and the pinned metadata snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pr121332 Add 2 tests for coverage gaps in PR ClickHouse#121332
…helpers for Trimmed to what the original change is about - a table on a `backup_metadata_only` storage policy has its data left out of a backup and a restore - with everything the branch cannot express removed: - `castStorage`, `DeferredTable` and `resolveStorageProxyLoading` come from #121332, which is not on this branch, so the casts are plain `std::dynamic_pointer_cast`. A table behind a `StorageProxy` is no longer resolved, so its data is backed up as usual rather than left out. - `warnBackupMetadataOnlyIgnored` and the lookups of the inner tables of a materialized view and a `TimeSeries` table are gone. They only logged, and the answer does not depend on them: the flag is ignored for both kinds either way. The test asserts the backups still succeed instead of asserting the warnings. `context` is unused in the overload that is left, and the includes the removed code needed are dropped. Co-Authored-By: Claude Opus 5 <[email protected]>
…helpers for Trimmed to what the original change is about - a table on a `backup_metadata_only` storage policy has its data left out of a backup and a restore - with everything the branch cannot express removed: - `castStorage`, `DeferredTable` and `resolveStorageProxyLoading` come from #121332, which is not on this branch, so the casts are plain `std::dynamic_pointer_cast`. A table behind a `StorageProxy` is no longer resolved, so its data is backed up as usual rather than left out. - `warnBackupMetadataOnlyIgnored` and the lookups of the inner tables of a materialized view and a `TimeSeries` table are gone. They only logged, and the answer does not depend on them: the flag is ignored for both kinds either way. The test asserts the backups still succeed instead of asserting the warnings. `context` is unused in the overload that is left, and the includes the removed code needed are dropped. Co-Authored-By: Claude Opus 5 <[email protected]>
A table in a database with
lazy_load_tablesis reached throughStorageTableProxy, so a cast of the catalog pointer to an engine type sees only the proxy and the table is silently skipped: it never shows up insystem.partsorsystem.replicas, andSYSTEM SYNC REPLICArefuses it.castStorage<T>(ptr, DeferredTable::Load | Skip)resolves the proxy chain before casting and replaces every such cast, and a style check forbids the raw form from now on. Eager tables are unaffected, andDistributed,Buffer,MaterializedPostgreSQL,MergeandMemoryare now always eager, since deferring them cancels background work or saves nothing. The rest of thelazy_load_tablesfixes stay in #113389.Closes: #117420
Closes: #122297
Related: #113389
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Tables in a database with
lazy_load_tableswere missing fromsystem.parts,system.replicasand related system tables, and refused by replica commands, after a restart.Workflow [PR]
Sync PR [sync-upstream/pr/121332]
Version info
26.10.1.1347-master(included in26.10and later)26.9.13.15,26.8.21.6,26.7.25.5,26.3.49.3