Skip to content

Don't store columns in Alias engine create_table_query - #115141

Merged
hanfei1991 merged 4 commits into
ClickHouse:masterfrom
eclbg:fix-alias-create-query
Oct 8, 2026
Merged

hanfei1991 merged 4 commits into
ClickHouse:masterfrom
eclbg:fix-alias-create-query

Conversation

@eclbg

@eclbg eclbg commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Before this change, table for Alias tables included the columns at the time of creation. This had mainly 2 problems:

  • The resulting query is not a valid CREATE TABLE query, as columns are rejected for Engine = Alias
  • Columns will gets tale if the target table changes

After this PR, the query no longer includes the columns and is therefore a valid query. This is visible in:

  • create_table_query column in system.tables
  • the .sql metadata file
  • SHOW CREATE TABLE
  • perhaps more places

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix create table query stored in metadata for Alias tables so it doesn't include columns, which is invalid.


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

Version info

  • Merged into: 26.10.1.1803-master (included in 26.10 and later)

It produces a query that's not valid, as columns are rejected
@clickhouse-gh clickhouse-gh Bot added the comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). label Sep 4, 2026
@evillique evillique self-assigned this Sep 11, 2026
@evillique evillique added the can be tested Allows running workflows for external contributors label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fa8f214]

Summary: ✅


AI Review

Summary

This PR fixes newly created Alias metadata and makes SHOW CREATE stop printing the legacy inlined schema, but it still misses the upgrade path for pre-existing on-disk aliases and the new SHOW CREATE path now bypasses the target-visibility guard entirely.

Findings
  • ❌ Blockers
    • [src/Interpreters/InterpreterShowCreateQuery.cpp:171] SHOW CREATE no longer enforces any target visibility check for Alias. A user who has SHOW COLUMNS on the alias but no visibility into the target can now learn the hidden target named in ENGINE = Alias(...), while system.tables.create_table_query still intentionally blanks that same declared definition unless StorageAlias::isDeclaredTargetGranted(...SHOW_TABLES...) passes. Suggested fix: keep stripping the legacy inlined columns, but continue to gate the declared definition on target visibility (likely SHOW_TABLES to match system.tables) or mask the target name before formatting.
  • ⚠️ Majors
    • [src/Interpreters/InterpreterCreateQuery.cpp:3803] [dismissed by author -- https://github.com/Don't store columns in Alias engine create_table_query #115141#discussion_r4109700650] The fix is still incomplete for upgrade users. DatabaseOnDisk::getCreateTableQueryImpl keeps returning the persisted AST from the old .sql metadata file, and system.tables.create_table_query renders that AST unchanged, so pre-existing aliases still surface the invalid CREATE TABLE ... (cols) ENGINE = Alias(...) definition. Clearing columns_list only in SHOW CREATE does not fix system.tables or the persisted metadata itself. Suggested fix: normalize Alias ASTs in the shared load/render path (or rewrite metadata on load) so every caller stops exposing the stale column list.
Final Verdict

❌ Not ready to merge: the new SHOW CREATE path introduces an alias-target metadata leak, and the stale persisted-metadata path for existing aliases is still unfixed.

LLVM Coverage Report

Measured on commit fa8f214.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 11, 2026
@clickhouse-gh clickhouse-gh Bot added comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. and removed comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). labels Sep 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit fa8f214949673076d91938ae1f71ba3efccac0f3 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

An `Alias` has no schema of its own, and this PR already stops newly created
aliases from persisting their target's columns. Older servers, however, inlined
the resolved columns into the stored definition, so `SHOW CREATE TABLE` of such
an alias still echoed the target's schema. Strip those columns on output so
`SHOW CREATE` shows the statement the user wrote (`ENGINE = Alias(...)`).

With the schema no longer exposed there, the target-side `SHOW COLUMNS` check on
`SHOW CREATE` is no longer needed and is removed; the remaining metadata faces
(`DESCRIBE`, `system.columns`, `COM_FIELD_LIST`, ...) keep their own checks.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@hanfei1991 hanfei1991 self-assigned this Oct 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: e80794c4-ac08-4568-b8f2-d9d2a4993cd8
  • MIRAI run: b65c1d6c-3a2f-4923-9b6d-78f5e7053fb5
  • PR check IDs:
    • clickbench_248467_1791407932
    • clickbench_248473_1791407932
    • clickbench_248479_1791407932
    • tpch_adapted_1_official_248490_1791407932
    • tpch_adapted_1_official_248502_1791407932
    • tpch_adapted_1_official_248539_1791407934

`SHOW CREATE TABLE` of an `Alias` no longer requires a grant on the target and no
longer exposes its schema, so remove the "SHOW CREATE without target permission"
cases that asserted `ACCESS_DENIED` from both metadata access-rights tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ast_create_query.columns_list->columns->children.clear();

if (query_ptr->as<ASTShowCreateViewQuery>())
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This strips the legacy inlined columns, but it also removes the only target-visibility check from SHOW CREATE for Alias. After this change, a user who has SHOW COLUMNS on the alias but no visibility into the target can still learn the hidden target name via ENGINE = Alias(...), even though system.tables.create_table_query still blanks that same declared definition unless StorageAlias::isDeclaredTargetGranted(...SHOW_TABLES...) passes.

That makes SHOW CREATE a privilege-bypass entrypoint into the alias metadata surface. Please keep the column stripping, but preserve a target grant check before formatting (likely SHOW_TABLES to match system.tables, or otherwise mask the target name too).

@hanfei1991
hanfei1991 added this pull request to the merge queue Oct 8, 2026
Merged via the queue into ClickHouse:master with commit 269d7ce Oct 8, 2026
300 of 301 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 8, 2026
@eclbg

eclbg commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks so much for pushing this over the line @hanfei1991

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 10, 2026
…solete

Since ClickHouse#115141, `SHOW CREATE TABLE` (and `SHOW CREATE TEMPORARY TABLE`) of an
`Alias` no longer throws `ACCESS_DENIED` without `SHOW COLUMNS` on the target;
it strips the inlined columns instead. `03636_storage_alias_metadata_access_rights`
and `05057_system_tables_temporary_alias_show_columns` asserted that refusal next
to the withheld `system.tables` columns, so after the master merge both failed on
exactly that line. Remove the two assertions and their comments, as ClickHouse#115141 did
for the same cases in master's copies of the 03636 tests.

The `system.tables` gate itself is unchanged. `create_table_query` is read from the
stored definition and is not stripped: an `Alias` stored by an older server still
returns the target's columns there (measured: `ATTACH TABLE ... (id UInt64, secret
String) ENGINE = Alias(...)` shows both columns in `create_table_query`, while
`SHOW CREATE TABLE` prints none). So the declared-target `SHOW COLUMNS` check still
protects those definitions; the two comments that justified it by parity with
`SHOW CREATE TABLE` now state that reason instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit to jh0x/ClickHouse that referenced this pull request Oct 20, 2026
An `Alias` has no schema of its own. Servers before 26.10 inlined the columns of
the target table into the stored definition, newer ones don't, so `RESTORE` over
an existing `Alias` table failed with `CANNOT_RESTORE_TABLE` when only one side
carried them.

Drop `columns_list` for `Alias` in `DDLAdjustingForBackupVisitor::visitStorage`,
the way it is already done for `System*` engines. The visitor runs on both sides
of the comparison, so both shapes normalize to the same text.

Closes: ClickHouse#124589
Caused by: ClickHouse#115141

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants