Skip to content

Commit c104ce8

Browse files
committed
Accept keywords as index type names in ALTER ADD INDEX
The parser was only accepting identifiers (token.IDENT) for index type names like "set" in "ADD INDEX idx c TYPE set(0)". However, "set" is tokenized as a keyword (token.SET). This fix allows keywords to be used as index type names and AFTER index names, matching ClickHouse behavior. Fixes tests: - 01932_alter_index_with_order (stmt5, stmt6) - 03629_storage_s3_disallow_index_alter (stmt3) - 02131_skip_index_not_materialized (stmt4)
1 parent f0aac10 commit c104ce8

4 files changed

Lines changed: 7 additions & 18 deletions

File tree

parser/parser.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5305,9 +5305,10 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
53055305
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "TYPE" {
53065306
p.nextToken()
53075307
// Type is a function call like bloom_filter(0.025) or vector_similarity('hnsw', 'L2Distance', 1)
5308+
// Note: Index types can be keywords (e.g., SET) so we accept both IDENT and keywords
53085309
pos := p.current.Pos
53095310
typeName := ""
5310-
if p.currentIs(token.IDENT) {
5311+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
53115312
typeName = p.current.Value
53125313
cmd.IndexType = typeName
53135314
p.nextToken()
@@ -5339,7 +5340,8 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
53395340
// Parse AFTER
53405341
if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "AFTER" {
53415342
p.nextToken()
5342-
if p.currentIs(token.IDENT) {
5343+
// Index name can be an identifier or keyword
5344+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
53435345
cmd.AfterIndex = p.current.Value
53445346
p.nextToken()
53455347
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true,
4-
"stmt6": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)