Skip to content

Move ALTER TABLE SETTINGS to the statement level - #320

Draft
Lance726 wants to merge 2 commits into
AfterShip:masterfrom
Lance726:fix/alter-table-settings-statement-level
Draft

Move ALTER TABLE SETTINGS to the statement level#320
Lance726 wants to merge 2 commits into
AfterShip:masterfrom
Lance726:fix/alter-table-settings-statement-level

Conversation

@Lance726

@Lance726 Lance726 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #319 — that PR's commit is this branch's base, so the diff below includes it. Merge #319 first; this PR's own change is the second commit.

SETTINGS on ALTER TABLE is query-level: ClickHouse accepts it once, after the last alter clause, and rejects it mid-statement.

It was parsed per clause instead, and only by ADD COLUMN, ADD INDEX, DETACH PARTITION and DROP PARTITION. Everything else ClickHouse accepts failed to parse:

ALTER TABLE t MODIFY COLUMN a Int64 SETTINGS alter_sync = 2;
ALTER TABLE t DROP COLUMN b SETTINGS alter_sync = 2;
ALTER TABLE t ADD COLUMN c Int, DROP COLUMN b SETTINGS alter_sync = 2;
ALTER TABLE t MATERIALIZE INDEX IF EXISTS idx SETTINGS mutations_sync = 2;

It is now parsed once in parseAlterTable, after the clause list, and rejected mid-statement as ClickHouse does.

Breaking AST change: Settings moves off those four clauses onto AlterTable.Settings. Formatted SQL is unchanged — only the output/ goldens move, not format/.

Verified against clickhouse-local 26.8.2.7.

Lance726 and others added 2 commits September 3, 2026 18:21
…ment

ADD INDEX had no SETTINGS clause, so a statement such as

  ALTER TABLE t ADD INDEX IF NOT EXISTS idx c TYPE minmax
    GRANULARITY 1 SETTINGS alter_sync = 2

failed to parse, while ADD COLUMN and the partition clauses already
accepted one. Parse it the same way they do.

The formatter also wrote the clause as `ADD IF NOT EXISTS INDEX`, which
ClickHouse rejects, so formatted output could not be parsed again. Split
the part of TableIndex.FormatSQL that follows the INDEX keyword so
ALTER TABLE can emit `ADD INDEX IF NOT EXISTS` instead.

Both forms were verified against clickhouse-local 26.8.2.7.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
SETTINGS on ALTER TABLE is a query-level clause: ClickHouse accepts it
once, after the last alter clause, and rejects it mid-statement.

  -- rejected by ClickHouse
  ALTER TABLE t ADD COLUMN c Int SETTINGS alter_sync = 2, DROP COLUMN b
  -- accepted by ClickHouse
  ALTER TABLE t ADD COLUMN c Int, DROP COLUMN b SETTINGS alter_sync = 2

It was instead parsed per clause, by ADD COLUMN, ADD INDEX, DETACH
PARTITION and DROP PARTITION only, so every other form failed to parse
even though ClickHouse accepts it:

  ALTER TABLE t MODIFY COLUMN a Int64 SETTINGS alter_sync = 2
  ALTER TABLE t DROP COLUMN b SETTINGS alter_sync = 2
  ALTER TABLE t ADD COLUMN c Int, DROP COLUMN b SETTINGS alter_sync = 2
  ALTER TABLE t MATERIALIZE INDEX IF EXISTS idx SETTINGS mutations_sync = 2

Parse it once in parseAlterTable instead, after the clause list, and
reject it mid-statement as ClickHouse does.

Formatted SQL is unchanged for the clauses that already accepted
SETTINGS: only the AST placement moves, so their format/ goldens do not
change.

Breaking AST change: AlterTableAddColumn.Settings,
AlterTableAddIndex.Settings, AlterTableDetachPartition.Settings and
AlterTableDropPartition.Settings are removed in favour of
AlterTable.Settings.

Every form above was verified against clickhouse-local 26.8.2.7, in both
directions: the SQL parses here, and this parser's formatted output is
accepted by ClickHouse.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Lance726
Lance726 marked this pull request as draft September 4, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant