Skip to content

Cherry pick #129818 to 26.3: Merge tables report rows and sizes only of the tables the user can see - #132134

Merged
PedroTadim merged 5 commits into
backport/26.3/129818from
cherrypick/26.3/129818
Nov 17, 2026
Merged

PedroTadim merged 5 commits into
backport/26.3/129818from
cherrypick/26.3/129818

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #129818

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 4 commits November 6, 2026 15:31
A `Merge` table or `merge()` reads only the matched tables the user has
`SHOW TABLES` on (#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]>
… 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]>
Merge tables report rows and sizes only of the tables the user can see
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

The conflicts come from master changes that are not on 26.3, and I resolved them without importing any of them:

  • IStorage.h, StorageMerge.cpp: 26.3 does not have the getColumnSizes(columns, calculate_subcolumn_sizes) overload, so only the tryGetColumnSizes(query_context) signature change is applied.
  • StorageAlias.{h,cpp}: 26.3 has neither the Alias chain grants of Require the privilege on every table in an Alias chain #118967 nor isTargetTableGranted, and an Alias target cannot be another Alias there. StorageAlias::tryGetColumnSizes filters the target's column sizes by SHOW_COLUMNS on the target.
  • StorageMerge.cpp, supportsTrivialCountOptimization: master also declines a child that has a row policy (Refactoring of row policy usage #118668). I kept the 26.3 check and added only the visibility and SELECT checks of this PR.
  • StorageTableFunction.h: 26.3 does not have the nestedIfResolved() forwards, and its proxy resolves the nested storage for getColumnSizes(). So tryGetColumnSizes() forwards to getNested() the same way.

Two more changes are needed on 26.3: the system.columns source keeps the query context (as on 26.8) to pass it to tryGetColumnSizes, and the test enables allow_experimental_alias_table_engine, because the Alias engine is experimental on 26.3.

On a 26.3 debug build (clang-21), 05616_merge_storage_hidden_tables_metadata passes 30 of 30 randomized runs. The official 26.3.63.123 binary fails it: it counts the hidden table in count(), total_rows and the column sizes.

I cannot push to cherrypick/26.3/129818. The branch on my fork has this PR's head e1e303332557 as an ancestor, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git resolve-26.3-cherrypick-129818
git push origin FETCH_HEAD:cherrypick/26.3/129818

26.3 lacks the alias grant checks on the target table, the row policy
check in `supportsTrivialCountOptimization` and the context argument of
`getInMemoryMetadataPtr`. The alias forwards the query context to its
target without filtering columns, as `system.columns` does there, and the
trivial count check keeps only the new `SELECT` requirement.

26.3 also lacks #116774, so a
table created from a table function reports no rows or column sizes at all;
the `StorageTableFunction` override and the `m_func` size checks of the
test are left out. The test enables the experimental `Alias` engine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim merged commit d76e808 into backport/26.3/129818 Nov 17, 2026
2 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.3/129818 branch November 17, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants