Skip to content

Commit 69f8e06

Browse files
committed
Fix MATERIALIZE/CLEAR INDEX IN PARTITION support
Add IN PARTITION clause parsing for CLEAR INDEX statements. Fix EXPLAIN output for MATERIALIZE INDEX IN PARTITION to show Partition without requiring PARTITION ID syntax. Normalize CLEAR_INDEX to DROP_INDEX in EXPLAIN output. Fixes 4 additional tests.
1 parent bc6998d commit 69f8e06

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

internal/explain/statements.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,10 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
13201320
if cmdType == ast.AlterClearColumn {
13211321
cmdType = ast.AlterDropColumn
13221322
}
1323+
// CLEAR_INDEX is shown as DROP_INDEX in EXPLAIN AST
1324+
if cmdType == ast.AlterClearIndex {
1325+
cmdType = ast.AlterDropIndex
1326+
}
13231327
// DELETE_WHERE is shown as DELETE in EXPLAIN AST
13241328
if cmdType == ast.AlterDeleteWhere {
13251329
cmdType = "DELETE"
@@ -1397,17 +1401,27 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
13971401
if cmd.Index != "" {
13981402
fmt.Fprintf(sb, "%s Identifier %s\n", indent, cmd.Index)
13991403
}
1404+
// CLEAR INDEX IN PARTITION clause
1405+
if cmd.Partition != nil {
1406+
fmt.Fprintf(sb, "%s Partition (children 1)\n", indent)
1407+
Node(sb, cmd.Partition, depth+2)
1408+
}
14001409
case ast.AlterMaterializeIndex:
14011410
if cmd.Index != "" {
14021411
fmt.Fprintf(sb, "%s Identifier %s\n", indent, cmd.Index)
14031412
}
1404-
// MATERIALIZE INDEX can have IN PARTITION ID clause
1405-
if cmd.Partition != nil && cmd.PartitionIsID {
1406-
if lit, ok := cmd.Partition.(*ast.Literal); ok {
1407-
fmt.Fprintf(sb, "%s Partition_ID Literal_\\'%s\\' (children 1)\n", indent, lit.Value)
1408-
Node(sb, cmd.Partition, depth+2)
1413+
// MATERIALIZE INDEX can have IN PARTITION or IN PARTITION ID clause
1414+
if cmd.Partition != nil {
1415+
if cmd.PartitionIsID {
1416+
if lit, ok := cmd.Partition.(*ast.Literal); ok {
1417+
fmt.Fprintf(sb, "%s Partition_ID Literal_\\'%s\\' (children 1)\n", indent, lit.Value)
1418+
Node(sb, cmd.Partition, depth+2)
1419+
} else {
1420+
fmt.Fprintf(sb, "%s Partition_ID (children 1)\n", indent)
1421+
Node(sb, cmd.Partition, depth+2)
1422+
}
14091423
} else {
1410-
fmt.Fprintf(sb, "%s Partition_ID (children 1)\n", indent)
1424+
fmt.Fprintf(sb, "%s Partition (children 1)\n", indent)
14111425
Node(sb, cmd.Partition, depth+2)
14121426
}
14131427
}
@@ -1660,12 +1674,15 @@ func countAlterCommandChildren(cmd *ast.AlterCommand) int {
16601674
if cmd.Index != "" {
16611675
children++
16621676
}
1677+
if cmd.Partition != nil {
1678+
children++
1679+
}
16631680
case ast.AlterMaterializeIndex:
16641681
if cmd.Index != "" {
16651682
children++
16661683
}
1667-
// MATERIALIZE INDEX can have IN PARTITION ID clause
1668-
if cmd.Partition != nil && cmd.PartitionIsID {
1684+
// MATERIALIZE INDEX can have IN PARTITION or IN PARTITION ID clause
1685+
if cmd.Partition != nil {
16691686
children++
16701687
}
16711688
case ast.AlterMaterializeColumn:

parser/parser.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,6 +4771,14 @@ func (p *Parser) parseAlterCommand() *ast.AlterCommand {
47714771
cmd.Index = p.current.Value
47724772
p.nextToken()
47734773
}
4774+
// Parse IN PARTITION clause
4775+
if p.currentIs(token.IN) {
4776+
p.nextToken() // skip IN
4777+
if p.currentIs(token.PARTITION) {
4778+
p.nextToken() // skip PARTITION
4779+
cmd.Partition = p.parseExpression(LOWEST)
4780+
}
4781+
}
47744782
} else if p.currentIs(token.COLUMN) {
47754783
cmd.Type = ast.AlterClearColumn
47764784
p.nextToken()
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt12": true,
4-
"stmt15": true,
5-
"stmt16": true,
6-
"stmt8": true,
7-
"stmt9": true
3+
"stmt8": true
84
}
95
}

0 commit comments

Comments
 (0)