Repository navigation
Reject ATTACH TABLE with storage clauses but no ENGINE - #104800
Algunenano merged 1 commit into
Conversation
`ATTACH TABLE name SETTINGS k = v;` (and the same with `ORDER BY`, `PARTITION BY`, etc.) without an explicit `ENGINE` would be parsed and then silently routed through the short-`ATTACH` path that reads the table definition from stored metadata, overwriting the user's input. Users saw no error and assumed their settings took effect. `ParserCreateQuery.cpp:697` allows `SETTINGS` without `ENGINE` to support `default_table_engine` on `CREATE`. For `ATTACH` the same syntax produced an `ASTStorage` with settings but no engine, which made the short-`ATTACH` detection at `InterpreterCreateQuery.cpp:1571` (`!create.storage->engine`) match and drop the user's clauses. The other non-engine storage clauses (`PARTITION BY`, `PRIMARY KEY`, `ORDER BY`, `SAMPLE BY`, `TTL`, `UNIQUE KEY`) have the same shape and the same bug. Now we reject `ATTACH TABLE` with `create.storage && !create.storage->engine && !create.columns_list` with `BAD_ARGUMENTS`, pointing users at the short-`ATTACH` form (`ATTACH TABLE t;`) or `ALTER TABLE` for changing settings after attach. The check fires before `ON CLUSTER` forwarding and before Replicated-database query enqueue, so distributed `ATTACH ... SETTINGS` is rejected at the initiator instead of silently dropping on each replica. Closes ClickHouse#104791. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pre-PR validation gate (see TASK.md):
Session: |
|
cc @Algunenano @tavplubix — could you review this? It tightens |
|
Workflow [PR], commit [b49ae90] Summary: ✅ AI ReviewSummaryThis PR rejects Final Verdict
|
LLVM Coverage Report
Changed lines: 100.00% (9/9) · Uncovered code |
Algunenano
left a comment
There was a problem hiding this comment.
I think this is ok. I don't expect this syntax exists in the wild, so although it's technically a breaking change it's fine
Apply the edit-changelog skill workflow to the autogenerated 26.5 section: add the release header, drop the NO CL ENTRY and NOT FOR CHANGELOG / INSIGNIFICANT sections, rescue user-visible entries into Bug Fix, Performance Improvement and Improvement, reconcile reverted PRs against the rest of the changelog (drop entries for ClickHouse#102801, ClickHouse#103547, ClickHouse#103858, ClickHouse#104800), record the isPrime / isProbablePrime revert-of-revert and follow-up PRs on the original entry, prune Build/Testing to user-affecting items, and apply a focused round of per-entry rewrites (proper-noun capitalization, backticked identifiers, common typos). Date, presentation URL and video URL in the release header are left as FIXME placeholders.
Re-land of ClickHouse#104800 with a narrower guard that does not break `ATTACH TABLE t SETTINGS log_comment = 'foo';`. PR ClickHouse#104800 was reverted in ClickHouse#105032 because it rejected that pattern, which internal CI relies on (reported by @Algunenano on ClickHouse#104791). `InterpreterSetQuery::applySettingsFromQuery` runs in `executeQueryImpl` before `InterpreterCreateQuery::createTable` and hoists session settings out of `create.storage->settings` into the context, resetting `storage->settings` to `nullptr` when nothing engine-specific is left. The reverted guard fired only on the existence of an `ASTStorage` without an `engine`, so by the time it ran the storage object had already been emptied — rejecting the legitimate `log_comment` shape. The narrower guard checks the individual non-engine fields (`partition_by`, `primary_key`, `order_by`, `sample_by`, `ttl_table`, `unique_key`, `settings`) so it only rejects when there is something the short-`ATTACH` path would actually drop: ATTACH TABLE t; OK (short ATTACH) ATTACH TABLE t SETTINGS log_comment = 'foo'; OK (session bind) ATTACH TABLE t SETTINGS index_granularity = 100; BAD_ARGUMENTS ATTACH TABLE t SETTINGS max_part_loading_threads = 16; BAD_ARGUMENTS ATTACH TABLE t ORDER BY id; BAD_ARGUMENTS ATTACH TABLE t PARTITION BY id; BAD_ARGUMENTS Regression test `04247_attach_table_storage_clauses_without_engine_error` covers all six cases. Closes ClickHouse#104791. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…1-narrower-attach-table-storage-guard Reject ATTACH TABLE with non-engine storage clauses (narrower guard, re-land of ClickHouse#104800)
…1-narrower-attach-table-storage-guard Reject ATTACH TABLE with non-engine storage clauses (narrower guard, re-land of ClickHouse#104800)
Fixes #104791. Reported by @clickgapai during automated review of merged PR #73120; @zlareb1 flagged it for fix.
Motivation
ATTACH TABLE name SETTINGS k = v;(and the same withORDER BY,PARTITION BY, etc.) without an explicitENGINEwould be parsed and then silently routed through the short-ATTACHpath that reads the table definition from stored metadata, overwriting the user's input. Users saw no error and assumed their settings took effect.Reproducer (from the issue):
Root cause
ParserCreateQuery.cpp:697allowsSETTINGSwithoutENGINEfor tables in order to supportdefault_table_engineonCREATE. ForATTACHthe same syntax produced anASTStoragewith settings but no engine, which made the short-ATTACHdetection atInterpreterCreateQuery.cpp:1571(!create.storage->engine) match and discard the user's clauses while reading the full stored definition. The other non-engine storage clauses (PARTITION BY,PRIMARY KEY,ORDER BY,SAMPLE BY,TTL,UNIQUE KEY) have the same shape and the same bug.Fix
Reject the ambiguous case before entering the short-
ATTACHbranch. When the user provided storage clauses without anENGINEand no columns list, throwBAD_ARGUMENTSand point them at the short form (ATTACH TABLE t;) orALTER TABLEfor changing settings after attach.The check fires before
ON CLUSTERforwarding and before Replicated-database query enqueue, so distributedATTACH ... SETTINGSis rejected at the initiator instead of silently dropping on each replica.Tests
Added
tests/queries/0_stateless/04237_attach_table_settings_without_engine_error.sqlcovering:ATTACH TABLE t SETTINGS k = v;—BAD_ARGUMENTSATTACH TABLE t ORDER BY id;—BAD_ARGUMENTSATTACH TABLE t PARTITION BY id;—BAD_ARGUMENTSATTACH TABLE t;— still works (positive control)Verified locally with the debug build that the bug reproduces without the fix and is rejected with
BAD_ARGUMENTSwith the fix.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ATTACH TABLE name <storage clauses>;without anENGINEand without a columns list (e.g.ATTACH TABLE t SETTINGS max_part_loading_threads = 16;orATTACH TABLE t ORDER BY id;) used to silently ignore the user-provided storage clauses and re-attach the table with its stored definition. Now this is rejected withBAD_ARGUMENTSso users can notice and use the short formATTACH TABLE t;orALTER TABLE ... MODIFY SETTINGinstead.Documentation entry for user-facing changes
Version info
26.5.1.668