Repository navigation
Merge tables report rows and sizes only of the tables the user can see - #129818
Conversation
A `Merge` table or `merge()` reads only the matched tables the user has `SHOW TABLES` on (ClickHouse#78339), but its metadata-only answers walked every matched table: the trivial count (`SELECT count()` with `apply_patch_parts = 0, apply_mutations_on_fly = 0`), `system.tables` `total_rows`/`total_bytes` and `system.columns` sizes included the rows and on-disk size of a table the user holds no privilege on, and the trivial count answered for a visible child the user cannot read. `totalRows`/`totalBytes`, `supportsTrivialCountOptimization` and `tryGetColumnSizes` now enumerate the children with the query context and skip those without `SHOW TABLES`, like `getSelectedTables` does. The trivial count is also declined for a visible child with no `SELECT` on any column, so the read path raises its `ACCESS_DENIED`. `tryGetColumnSizes` takes the query context (its only caller is `system.columns`), and the Merge sums each visible child's own context-aware sizes, so a nested `Merge` or an `Alias` over a `Merge` filters its own children too. `Alias`, `StorageProxy` and `StorageTableFunctionProxy` forward the context. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The metadata walks of a `Merge` table now ask for `SHOW TABLES` (and, for the trivial count, `SELECT`) on the whole database once per database, like `getSelectedTables` does, and check a single table only when the database-wide grant is missing. A fully granted user pays no per-table access check, and the query's `used_privileges` no longer lists every matched table. An `Alias` reports column sizes only when the user can see its target, as its `totalRows`/`totalBytes` already do, so an `Alias` child of a `Merge` no longer reports the sizes of a hidden target in `system.columns`. Drop the `StorageProxy::tryGetColumnSizes` forwarder: no `StorageProxy` wraps a `Merge` or an `Alias`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261106-192000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261106-175000 |
|
cc @PedroTadim @vitlibar, could you review this and add the |
|
Workflow [PR], commit [ba1de54] Summary: ✅
AI ReviewSummaryThis PR makes metadata-only answers from Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units721 translation units recompiled, 5961 s compile time in total, 721 of them have a recent master baseline. |
CI finish ledger - 3b2b763Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
No job was dropped, and Session id: cron:our-pr-ci-monitor:20261107-023005 |
|
🕵️ @groeneai The fix looks right to me. Every metadata-only answer of One question about Nit: |
… see `system.columns` shows a table's per-column sizes only for the columns the user has `SHOW COLUMNS` on. Through a Merge table they needed only `SHOW TABLES` on the child, so a user with `SHOW TABLES ON db.t2` (or a column-level grant such as `SELECT(id)`) got the other columns' sizes of `t2` added into the Merge table's sizes. `StorageMerge::tryGetColumnSizes` now adds a child's column size only when the user has `SHOW COLUMNS` on that column of the child, the check `system.columns` applies to the child itself. An Alias child forwards its target's sizes, so `StorageAlias::tryGetColumnSizes` now keeps only the columns granted `SHOW COLUMNS` through the alias chain, as `system.columns` does for an Alias table read directly. This replaces its `SHOW TABLES` guard on the target (which `SHOW COLUMNS` implies), so a Merge over an Alias of a hidden table now reports the sizes of its other children instead of none. `total_rows`/`total_bytes` keep the `SHOW TABLES` rule: `system.tables` shows them for such a table directly. Rename the test to the next free number (`add-test`): 03400 -> 05616. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Not intended: a size seen through
Compressed bytes of
The test is now |
Backport #129818 to 26.10: Merge tables report rows and sizes only of the tables the user can see
Cherry pick #129818 to 26.9: Merge tables report rows and sizes only of the tables the user can see
Cherry pick #129818 to 26.8: Merge tables report rows and sizes only of the tables the user can see
Cherry pick #129818 to 26.3: Merge tables report rows and sizes only of the tables the user can see
…the tables the user can see
…the tables the user can see
…the tables the user can see
Backport #129818 to 26.8: Merge tables report rows and sizes only of the tables the user can see
Backport #129818 to 26.9: Merge tables report rows and sizes only of the tables the user can see
Backport #129818 to 26.3: Merge tables report rows and sizes only of the tables the user can see
Related: #129597
Related: #129730
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
Mergetable and themergetable function no longer count the matched tables the user cannot see (noSHOW TABLES) whencount()is answered from metadata or insystem.tablestotal_rows/total_bytes, and theirsystem.columnssizes include only the columns the user can see (SHOW COLUMNS) on each matched table. Before, these disclosed the row count and size of tables the user has no access to, while reading the same data skipped them.Description
On 26.8.2.3 and 26.10.2.103, a user with
SELECTon aMergetablemovert1andt2and ont1only getsSELECT count() FROM m SETTINGS apply_patch_parts = 0, apply_mutations_on_fly = 0= 6 instead of 3, andsystem.tablesshowstotal_rows/total_bytesofmas 6/1502 instead of 3/751: the size of a table they cannot even list.Root cause: the read (
ReadFromMerge::getSelectedTables) skips matched tables withoutSHOW TABLES(#78339) and checksSELECTon the rest, but the metadata-only answers ofStorageMerge(totalRows/totalBytes,supportsTrivialCountOptimization,tryGetColumnSizes) went through every matched table with no check.Change: these now enumerate with the query context and skip tables without
SHOW TABLES, asking the database-wide grant once per database like the read does. The trivial count is declined for a visible table the user cannot read, so the read raises itsACCESS_DENIED.IStorage::tryGetColumnSizestakes the query context (its only caller issystem.columns), so a nestedMerge, anAliasover aMergeandCREATE TABLE ... AS merge(...)filter too. A child's column size is added only withSHOW COLUMNSon that column, the checksystem.columnsmakes for the child itself; anAliaskeeps only the columns granted through its chain.Unchanged: the plan-shape walks (prewhere, subcolumns, processing stage) still look at hidden tables;
Bufferover a hidden destination is #129801. Cost: within noise for a fully granted user; a partially granted user pays one check per matched table, like the read (~+11% CPU for a trivial count over 1000 tables, debug build).Validation: the new test
05616_merge_storage_hidden_tables_metadatafails on master in every leak case and passes 50/50 with randomized settings.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/129818]
Version info
26.11.1.1848-master(included in26.11and later)26.10.5.45,26.9.31.21,26.8.39.19,26.3.66.12