Repository navigation
Don't store columns in Alias engine create_table_query - #115141
Conversation
It produces a query that's not valid, as columns are rejected
|
Workflow [PR], commit [fa8f214] Summary: ✅
AI ReviewSummaryThis PR fixes newly created Findings
Final Verdict❌ Not ready to merge: the new LLVM Coverage ReportMeasured on commit fa8f214.
Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code |
Build profile diff (arm_release)Commit 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]>
|
📊 Cloud Performance Report ✅ AI verdict: 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
|
`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>()) | ||
| { |
There was a problem hiding this comment.
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).
269d7ce
|
Thanks so much for pushing this over the line @hanfei1991 |
…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]>
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]>
Before this change, table for Alias tables included the columns at the time of creation. This had mainly 2 problems:
CREATE TABLEquery, as columns are rejected forEngine = AliasAfter this PR, the query no longer includes the columns and is therefore a valid query. This is visible in:
create_table_querycolumn insystem.tables.sqlmetadata fileSHOW CREATE TABLEChangelog category (leave one):
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
26.10.1.1803-master(included in26.10and later)