Support CREATE INDEX with functional index parts#753
Merged
Conversation
Previously CREATE INDEX with a functional index (e.g. `((`a` IS NULL))`) was rejected. The parser already exposes the expression via IndexPartSpecification.Expr, so use IndexPartSpecification.Restore() which handles both column refs (with prefix lengths) and expressions. Fixes block#444.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the CREATE INDEX → ALTER TABLE ... ADD INDEX rewrite so functional index parts (expression-based key parts) are supported, leveraging TiDB parser’s IndexPartSpecification.Expr and Restore().
Changes:
- Rewrite
convertCreateIndexToAlterTableto build index parts viaIndexPartSpecification.Restore()(supports both column parts with prefix lengths and(expr)parts). - Add/adjust statement parsing tests to validate functional index and mixed functional + column index rewrites.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/statement/statement.go | Uses TiDB AST restore to serialize index parts, enabling functional index support in CREATE INDEX rewrite. |
| pkg/statement/statement_test.go | Updates coverage to assert successful rewrite for functional and mixed functional/plain index parts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aparajon
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CREATE INDEX idx ON t1 ((aIS NULL))was rejected with "cannot convert functional index to ALTER TABLE statement". The TiDB parser already exposes the expression viaIndexPartSpecification.Expr, so the rewrite can handle it.convertCreateIndexToAlterTablewithIndexPartSpecification.Restore(), which uniformly handles plain columns (with prefix lengths) and(expr)parts.Fixes #444.
Test plan
go test ./pkg/statement/passes, including a new case forCREATE INDEX idx ON t1 ((aIS NULL))and a mixed(a, (LOWER(b)))case.🤖 Generated with Claude Code