Skip to content

Commit 5f1d19c

Browse files
committed
Add CONSTRAINT ASSUME support in CREATE TABLE parsing
Previously only CONSTRAINT ... CHECK was supported. Now also supports CONSTRAINT ... ASSUME which is used for query optimization hints.
1 parent cd205b3 commit 5f1d19c

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

parser/parser.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ func (p *Parser) parseCreateTable(create *ast.CreateQuery) {
20442044
create.Projections = append(create.Projections, proj)
20452045
}
20462046
} else if p.currentIs(token.CONSTRAINT) {
2047-
// Parse CONSTRAINT name CHECK (expression)
2047+
// Parse CONSTRAINT name CHECK/ASSUME (expression)
20482048
p.nextToken() // skip CONSTRAINT
20492049
constraintName := p.parseIdentifierName() // constraint name
20502050
if p.currentIs(token.CHECK) {
@@ -2055,6 +2055,14 @@ func (p *Parser) parseCreateTable(create *ast.CreateQuery) {
20552055
Expression: p.parseExpression(LOWEST),
20562056
}
20572057
create.Constraints = append(create.Constraints, constraint)
2058+
} else if p.currentIs(token.IDENT) && strings.ToUpper(p.current.Value) == "ASSUME" {
2059+
p.nextToken() // skip ASSUME
2060+
constraint := &ast.Constraint{
2061+
Position: p.current.Pos,
2062+
Name: constraintName,
2063+
Expression: p.parseExpression(LOWEST),
2064+
}
2065+
create.Constraints = append(create.Constraints, constraint)
20582066
} else {
20592067
// Skip other constraint types we don't know about
20602068
for !p.currentIs(token.COMMA) && !p.currentIs(token.RPAREN) && !p.currentIs(token.EOF) {
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true,
4-
"stmt18": true,
5-
"stmt21": true,
6-
"stmt24": true,
7-
"stmt27": true,
8-
"stmt30": true,
9-
"stmt33": true
10-
}
11-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt18": true,
4-
"stmt5": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt28": true,
4-
"stmt40": true,
5-
"stmt8": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": 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-
"stmt2": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)