Skip to content

Commit cd7d6e1

Browse files
kyleconroyclaude
andcommitted
Add OPTIMIZE_FOR_SEQUENTIAL_KEY index option support
Add parsing for OPTIMIZE_FOR_SEQUENTIAL_KEY index option in: - Column-level INDEX definitions - Table-level INDEX definitions - Inline index definitions Also fix table-level INDEX WITH options to properly handle ON/OFF state options (not just expression options). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1efd00f commit cd7d6e1

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

parser/marshal.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6464,7 +6464,8 @@ func (p *Parser) parseColumnDefinition() (*ast.ColumnDefinition, error) {
64646464
indexDef.IndexOptions = append(indexDef.IndexOptions, opt)
64656465
} else if optionName == "PAD_INDEX" || optionName == "STATISTICS_NORECOMPUTE" ||
64666466
optionName == "ALLOW_ROW_LOCKS" || optionName == "ALLOW_PAGE_LOCKS" ||
6467-
optionName == "DROP_EXISTING" || optionName == "SORT_IN_TEMPDB" {
6467+
optionName == "DROP_EXISTING" || optionName == "SORT_IN_TEMPDB" ||
6468+
optionName == "OPTIMIZE_FOR_SEQUENTIAL_KEY" {
64686469
// ON/OFF options
64696470
stateUpper := strings.ToUpper(p.curTok.Literal)
64706471
optState := "On"
@@ -6473,12 +6474,13 @@ func (p *Parser) parseColumnDefinition() (*ast.ColumnDefinition, error) {
64736474
}
64746475
p.nextToken()
64756476
optKind := map[string]string{
6476-
"PAD_INDEX": "PadIndex",
6477-
"STATISTICS_NORECOMPUTE": "StatisticsNoRecompute",
6478-
"ALLOW_ROW_LOCKS": "AllowRowLocks",
6479-
"ALLOW_PAGE_LOCKS": "AllowPageLocks",
6480-
"DROP_EXISTING": "DropExisting",
6481-
"SORT_IN_TEMPDB": "SortInTempDB",
6477+
"PAD_INDEX": "PadIndex",
6478+
"STATISTICS_NORECOMPUTE": "StatisticsNoRecompute",
6479+
"ALLOW_ROW_LOCKS": "AllowRowLocks",
6480+
"ALLOW_PAGE_LOCKS": "AllowPageLocks",
6481+
"DROP_EXISTING": "DropExisting",
6482+
"SORT_IN_TEMPDB": "SortInTempDB",
6483+
"OPTIMIZE_FOR_SEQUENTIAL_KEY": "OptimizeForSequentialKey",
64826484
}[optionName]
64836485
indexDef.IndexOptions = append(indexDef.IndexOptions, &ast.IndexStateOption{
64846486
OptionKind: optKind,

parser/parse_ddl.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5567,22 +5567,39 @@ func (p *Parser) parseAlterTableAddStatement(tableName *ast.SchemaObjectName) (*
55675567
optionName := strings.ToUpper(p.curTok.Literal)
55685568
p.nextToken()
55695569

5570-
if p.curTok.Type != TokenEquals {
5571-
return nil, fmt.Errorf("expected = after option name, got %s", p.curTok.Literal)
5572-
}
5573-
p.nextToken() // consume =
5574-
5575-
// Parse option value
5576-
expr, err := p.parseScalarExpression()
5577-
if err != nil {
5578-
return nil, err
5570+
if p.curTok.Type == TokenEquals {
5571+
p.nextToken() // consume =
55795572
}
55805573

5581-
option := &ast.IndexExpressionOption{
5582-
OptionKind: convertIndexOptionKind(optionName),
5583-
Expression: expr,
5574+
// Check for ON/OFF state options
5575+
valueUpper := strings.ToUpper(p.curTok.Literal)
5576+
if valueUpper == "ON" || valueUpper == "OFF" || p.curTok.Type == TokenOn {
5577+
state := "On"
5578+
if valueUpper == "OFF" {
5579+
state = "Off"
5580+
}
5581+
p.nextToken() // consume ON/OFF
5582+
option := &ast.IndexStateOption{
5583+
OptionKind: convertIndexOptionKind(optionName),
5584+
OptionState: state,
5585+
}
5586+
indexDef.IndexOptions = append(indexDef.IndexOptions, option)
5587+
} else {
5588+
// Parse expression option value
5589+
expr, err := p.parseScalarExpression()
5590+
if err != nil {
5591+
// Skip on error
5592+
if p.curTok.Type == TokenComma {
5593+
p.nextToken()
5594+
}
5595+
continue
5596+
}
5597+
option := &ast.IndexExpressionOption{
5598+
OptionKind: convertIndexOptionKind(optionName),
5599+
Expression: expr,
5600+
}
5601+
indexDef.IndexOptions = append(indexDef.IndexOptions, option)
55845602
}
5585-
indexDef.IndexOptions = append(indexDef.IndexOptions, option)
55865603

55875604
if p.curTok.Type == TokenComma {
55885605
p.nextToken()

parser/parse_statements.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,13 @@ func (p *Parser) parseInlineIndexDefinition() (*ast.IndexDefinition, error) {
622622
}
623623
indexDef.IndexOptions = append(indexDef.IndexOptions, opt)
624624
p.nextToken()
625-
case "PAD_INDEX", "STATISTICS_NORECOMPUTE", "ALLOW_ROW_LOCKS", "ALLOW_PAGE_LOCKS":
625+
case "PAD_INDEX", "STATISTICS_NORECOMPUTE", "ALLOW_ROW_LOCKS", "ALLOW_PAGE_LOCKS", "OPTIMIZE_FOR_SEQUENTIAL_KEY":
626626
optionKindMap := map[string]string{
627-
"PAD_INDEX": "PadIndex",
628-
"STATISTICS_NORECOMPUTE": "StatisticsNoRecompute",
629-
"ALLOW_ROW_LOCKS": "AllowRowLocks",
630-
"ALLOW_PAGE_LOCKS": "AllowPageLocks",
627+
"PAD_INDEX": "PadIndex",
628+
"STATISTICS_NORECOMPUTE": "StatisticsNoRecompute",
629+
"ALLOW_ROW_LOCKS": "AllowRowLocks",
630+
"ALLOW_PAGE_LOCKS": "AllowPageLocks",
631+
"OPTIMIZE_FOR_SEQUENTIAL_KEY": "OptimizeForSequentialKey",
631632
}
632633
state := strings.ToUpper(p.curTok.Literal)
633634
optState := "Off"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)