Repository navigation
Reject CREATE TABLE ... CLONE AS SELECT / table function - #105004
Conversation
|
Workflow [PR], commit [55aeb12] Summary: ✅
AI ReviewSummaryThis PR closes the silent misbehavior around Final Verdict
LLVM Coverage ReportMeasured on commit 55aeb12.
Changed lines: Changed C/C++ lines covered: 25/25 (100.00%) · Uncovered code |
The parser accepted CREATE TABLE t CLONE AS SELECT ... and CREATE TABLE t CLONE AS <table_function>, but neither shape has partitions to attach, so the CLONE keyword was silently ignored and the table was created as a plain CREATE ... AS SELECT. Reject these shapes in getTablePropertiesAndNormalizeCreateQuery with BAD_ARGUMENTS. The check is gated to fresh user CREATE only — pre-fix the AS-table-function shape was persisted into .sql metadata, and rejecting on ATTACH would break loading of any such legacy table on upgrade. Also fix ASTCreateQuery::formatQueryImpl: the `if (select)` branch did not emit CLONE, so an AST round-trip silently dropped the keyword. The randomized-settings injection in clickhouse-test round-trips queries through this formatter, which is how the gap surfaced. Fixes ClickHouse#104994
ae90c08 to
5fb381c
Compare
|
This was fixed by #105146. Let's update the branch. |
The guard added in `getTablePropertiesAndNormalizeCreateQuery` only fired for a fresh `CREATE` (`mode <= CREATE`). A user-supplied full `ATTACH` definition — one that carries an explicit column list (and an engine for the `SELECT` form) — is not the short-attach path: `attach_short_syntax` is false, so it goes through the create-like path with `mode == ATTACH` and bypassed the guard. `isCreateQueryWithImmediateInsertSelect` returns false for `attach` and the clone partition-attach path requires `as_table_saved`, so `CLONE AS SELECT` / `CLONE AS table_function` were silently ignored for such `ATTACH` queries, exactly as they were for `CREATE` before this fix. Extend the guard to also reject `is_clone_as && as_table.empty()` for a user-supplied full `ATTACH` (`mode == ATTACH && !attach_short_syntax`), while leaving short `ATTACH` (`ATTACH TABLE t;`) and `SECONDARY_CREATE` (`DatabaseReplicated` internal queries, `RESTORE`) permissive so previously-validated metadata that persisted these forms still loads. Server startup is unaffected: it loads tables via `createTableFromAST`, which never calls this function. Adds full-`ATTACH` regression cases to `04238_clone_as_select_rejected`. Addresses review feedback on ClickHouse#105004 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review's "Request changes" verdict (full The guard in The guard now also rejects Added regression cases to |
|
The only red check is AST fuzzer (amd_debug) — The failing query is a fuzzer-mutated This signature has failed 279 times over the last 6 months across ~249 unrelated PRs (e.g. #105714, #106215, #107125, #88234, #86768, #108055, #79091, #109107, #108414). It was tracked by the now-closed #106358 (exact STID All other checks are green and the PR is approved. |
|
Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
🕵 Merged Integration tests (amd_tsan, 5/6) — The merge is clean and needed no code changes; both changed translation units ( |
|
Dear @SmitaRKulkarni, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
🕵 @groeneai, investigate the unrelated stress-test failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105004&sha=5fb11a63606e551ca261911c6db55867bb8a450c&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29. Both failing stress jobs hit |
|
Both failing stress jobs are the same trunk defect, and a fix PR is already open: #113242.
Aborting queries, read from Both carry Root cause: Verified both directions locally, master Not caused by this PR: 30d CIDB gives 22 rows / 22 distinct PRs for 2508-348f and 4 / 4 for 2508-3775, with 0 true-master rows in either and one hit per PR. #113242 is sequenced behind #113735, which currently has CHANGES_REQUESTED from @ novikd. That ruling is the unblock. |
|
🕵 Merged The only red on Status unchanged otherwise: approved by @SmitaRKulkarni, AI review ✅, zero unresolved review threads. Ready for a maintainer to merge once CI is green. |
|
🕵 Merged |
…dJSON` The AI review pointed out that `ASTCreateQuery::readJSON` never constrained `is_clone_as`, so a crafted `clickhouse_json` payload could put the flag on a view / dictionary form or on a source-less table. Since this pull request makes `formatQueryImpl` emit `CLONE` for the `AS SELECT` shape as well, such a payload now formats into DDL that the SQL parser cannot read back, for example `CREATE VIEW v CLONE AS SELECT 1`. `CLONE` is set only by `ParserCreateTableQuery`, only for tables, and only in front of an `AS <source>`; it is also mutually exclusive with `EMPTY`. Validate exactly that at the JSON boundary, alongside the existing `POPULATE` / `EMPTY` shape checks, and cover it with `05054_ast_json_clone_as_shape`.
The `05054` slot filled up with other tests on master in the meantime.
|
🕵 Pushed
Verified locally with a freshly built The single red on the previous head
|
|
@tuanpach @SmitaRKulkarni @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
The
CREATE TABLE ... CLONE AS <source>clause is intended to clone a real on-disk source table — the partition-attach step performed after table creation needs actual partitions to copy. The parser, however, also acceptedCREATE TABLE t CLONE AS SELECT ...andCREATE TABLE t CLONE AS <table_function>. Neither shape has partitions to attach, so theCLONEkeyword was silently ignored and the table was created as a plainCREATE ... AS SELECTwith an inferred schema andORDER BY tuple().This PR rejects both shapes early in
getTablePropertiesAndNormalizeCreateQuerywithBAD_ARGUMENTS, so the user gets a clear error instead of silent misbehavior. It also fixes a related defect inASTCreateQuery::formatQueryImpl: theif (select)branch did not calladd_clone_if_needed, so an AST format round-trip silently droppedCLONEfromCLONE AS SELECT. The randomized-settings injection inclickhouse-testround-trips queries through this formatter, which is how the gap surfaced.Closes: #104994
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
CREATE TABLE ... CLONE AS SELECT ...andCREATE TABLE ... CLONE AS <table_function>silently ignoring theCLONEkeyword and creating a plainCREATE ... AS SELECTinstead. These shapes are now rejected withBAD_ARGUMENTS.Documentation entry for user-facing changes
CLONE ASdocumentation, which only describes theCLONE AS <table>form.Workflow [PR]
Sync PR [sync-upstream/pr/105004]