Skip to content

Commit 9e6b8a4

Browse files
committed
Fix optimizer hint parsing for keyword tokens like ORDER GROUP
- Add handling for TokenOrder and TokenGroup in parseOptimizerHint - Properly parse two-word hints like ORDER GROUP, HASH GROUP, LOOP JOIN - Enable BaselinesCommon_DeleteStatementTests, BaselinesCommon_UpdateStatementTests, DeleteStatementTests, and UpdateStatementTests
1 parent 642df74 commit 9e6b8a4

5 files changed

Lines changed: 37 additions & 4 deletions

File tree

parser/parse_select.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,26 @@ func (p *Parser) parseOptimizerHint() (ast.OptimizerHintBase, error) {
15371537
return &ast.OptimizerHint{HintKind: "Use"}, nil
15381538
}
15391539

1540+
// Handle keyword tokens that can be optimizer hints (ORDER, GROUP, etc.)
1541+
if p.curTok.Type == TokenOrder || p.curTok.Type == TokenGroup {
1542+
hintKind := convertHintKind(p.curTok.Literal)
1543+
firstWord := strings.ToUpper(p.curTok.Literal)
1544+
p.nextToken()
1545+
1546+
// Check for two-word hints like ORDER GROUP
1547+
if (firstWord == "ORDER" || firstWord == "HASH" || firstWord == "MERGE" ||
1548+
firstWord == "CONCAT" || firstWord == "LOOP" || firstWord == "FORCE") &&
1549+
(p.curTok.Type == TokenIdent || p.curTok.Type == TokenGroup) {
1550+
secondWord := strings.ToUpper(p.curTok.Literal)
1551+
if secondWord == "GROUP" || secondWord == "JOIN" || secondWord == "UNION" ||
1552+
secondWord == "ORDER" {
1553+
hintKind = hintKind + convertHintKind(p.curTok.Literal)
1554+
p.nextToken()
1555+
}
1556+
}
1557+
return &ast.OptimizerHint{HintKind: hintKind}, nil
1558+
}
1559+
15401560
if p.curTok.Type != TokenIdent && p.curTok.Type != TokenLabel {
15411561
// Skip unknown tokens to avoid infinite loop
15421562
p.nextToken()
@@ -1646,8 +1666,21 @@ func (p *Parser) parseOptimizerHint() (ast.OptimizerHintBase, error) {
16461666
default:
16471667
// Handle generic hints
16481668
hintKind := convertHintKind(p.curTok.Literal)
1669+
firstWord := strings.ToUpper(p.curTok.Literal)
16491670
p.nextToken()
16501671

1672+
// Check for two-word hints like ORDER GROUP, HASH GROUP, etc.
1673+
if (firstWord == "ORDER" || firstWord == "HASH" || firstWord == "MERGE" ||
1674+
firstWord == "CONCAT" || firstWord == "LOOP" || firstWord == "FORCE") &&
1675+
p.curTok.Type == TokenIdent {
1676+
secondWord := strings.ToUpper(p.curTok.Literal)
1677+
if secondWord == "GROUP" || secondWord == "JOIN" || secondWord == "UNION" ||
1678+
secondWord == "ORDER" {
1679+
hintKind = hintKind + convertHintKind(p.curTok.Literal)
1680+
p.nextToken()
1681+
}
1682+
}
1683+
16511684
// Check if this is a literal hint (LABEL = value, etc.)
16521685
if p.curTok.Type == TokenEquals {
16531686
p.nextToken() // consume =
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+
{}
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)