Skip to content

Support SETTINGS in ALTER TABLE ADD INDEX and fix IF NOT EXISTS placement - #319

Merged
git-hulk merged 1 commit into
AfterShip:masterfrom
Lance726:fix/alter-table-add-index-settings
Sep 4, 2026
Merged

Support SETTINGS in ALTER TABLE ADD INDEX and fix IF NOT EXISTS placement#319
git-hulk merged 1 commit into
AfterShip:masterfrom
Lance726:fix/alter-table-add-index-settings

Conversation

@Lance726

@Lance726 Lance726 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Two fixes to ALTER TABLE … ADD INDEX.

It was the only alter clause that did not accept SETTINGS, so this failed to parse:

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

The formatter also wrote ADD IF NOT EXISTS INDEX, which ClickHouse rejects — formatted output could not be parsed again. It now writes ADD INDEX IF NOT EXISTS.

Verified against clickhouse-local 26.8.2.7. AlterTableAddIndex.Settings is new; no existing field changes.

…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>
@Lance726
Lance726 marked this pull request as draft September 4, 2026 03:02
@Lance726
Lance726 marked this pull request as ready for review September 4, 2026 03:22
@Lance726
Lance726 requested a review from git-hulk September 4, 2026 03:22
@git-hulk
git-hulk merged commit d05148b into AfterShip:master Sep 4, 2026
1 check passed
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.

2 participants