Skip to content

Commit dd9ab2b

Browse files
authored
Implement ALTER STATISTICS statement (#163)
1 parent 5770de8 commit dd9ab2b

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

ast/ast.go

+15
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (Revoke) isStatement() {}
7777
func (CreateSequence) isStatement() {}
7878
func (AlterSequence) isStatement() {}
7979
func (DropSequence) isStatement() {}
80+
func (AlterStatistics) isStatement() {}
8081
func (CreateVectorIndex) isStatement() {}
8182
func (DropVectorIndex) isStatement() {}
8283
func (Insert) isStatement() {}
@@ -287,6 +288,7 @@ func (Revoke) isDDL() {}
287288
func (CreateSequence) isDDL() {}
288289
func (AlterSequence) isDDL() {}
289290
func (DropSequence) isDDL() {}
291+
func (AlterStatistics) isDDL() {}
290292
func (CreateVectorIndex) isDDL() {}
291293
func (DropVectorIndex) isDDL() {}
292294

@@ -2566,6 +2568,19 @@ type RolePrivilege struct {
25662568
Names []*Ident // len(Names) > 0
25672569
}
25682570

2571+
// AlterStatistics is ALTER STATISTICS statement node.
2572+
//
2573+
// ALTER STATISTICS {{.Name | sql}} SET {{.Options | sql}}
2574+
type AlterStatistics struct {
2575+
// pos = Alter
2576+
// end = Options.end
2577+
2578+
Alter token.Pos // position of "ALTER" keyword
2579+
2580+
Name *Ident
2581+
Options *Options
2582+
}
2583+
25692584
// ================================================================================
25702585
//
25712586
// Types for Schema

ast/pos.go

+3
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,9 @@ func (e *ExecutePrivilegeOnTableFunction) End() token.Pos { return e.Names[len(e
892892
func (r *RolePrivilege) Pos() token.Pos { return r.Role }
893893
func (r *RolePrivilege) End() token.Pos { return r.Names[len(r.Names)-1].End() }
894894

895+
func (s *AlterStatistics) Pos() token.Pos { return s.Alter }
896+
func (s *AlterStatistics) End() token.Pos { return s.Options.End() }
897+
895898
// ================================================================================
896899
//
897900
// Types for Schema

ast/sql.go

+4
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,10 @@ func (r *RolePrivilege) SQL() string {
12381238
return sql
12391239
}
12401240

1241+
func (s *AlterStatistics) SQL() string {
1242+
return "ALTER STATISTICS " + s.Name.SQL() + " SET " + s.Options.SQL()
1243+
}
1244+
12411245
// ================================================================================
12421246
//
12431247
// Types for Schema

parser.go

+15
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,8 @@ func (p *Parser) parseDDL() ast.DDL {
21802180
return p.parseAlterSequence(pos)
21812181
case p.Token.IsKeywordLike("CHANGE"):
21822182
return p.parseAlterChangeStream(pos)
2183+
case p.Token.IsKeywordLike("STATISTICS"):
2184+
return p.parseAlterStatistics(pos)
21832185
}
21842186
p.panicfAtToken(&p.Token, "expected pseudo keyword: TABLE, CHANGE, but: %s", p.Token.AsString)
21852187
case p.Token.IsKeywordLike("DROP"):
@@ -3408,6 +3410,19 @@ func (p *Parser) parseSchemaType() ast.SchemaType {
34083410
panic(p.errorfAtToken(&p.Token, "expected token: ARRAY, <ident>, but: %s", p.Token.Kind))
34093411
}
34103412

3413+
func (p *Parser) parseAlterStatistics(pos token.Pos) *ast.AlterStatistics {
3414+
p.expectKeywordLike("STATISTICS")
3415+
name := p.parseIdent()
3416+
p.expect("SET")
3417+
options := p.parseOptions()
3418+
3419+
return &ast.AlterStatistics{
3420+
Alter: pos,
3421+
Name: name,
3422+
Options: options,
3423+
}
3424+
}
3425+
34113426
var scalarSchemaTypes = []string{
34123427
"BOOL",
34133428
"INT64",
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--- alter_statistics.sql
2+
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
3+
--- AST
4+
&ast.AlterStatistics{
5+
Alter: 0,
6+
Name: &ast.Ident{
7+
NamePos: 17,
8+
NameEnd: 42,
9+
Name: "auto_20191128_14_47_22UTC",
10+
},
11+
Options: &ast.Options{
12+
Options: 47,
13+
Rparen: 70,
14+
Records: []*ast.OptionsDef{
15+
&ast.OptionsDef{
16+
Name: &ast.Ident{
17+
NamePos: 56,
18+
NameEnd: 64,
19+
Name: "allow_gc",
20+
},
21+
Value: &ast.BoolLiteral{
22+
ValuePos: 65,
23+
Value: false,
24+
},
25+
},
26+
},
27+
},
28+
}
29+
30+
--- SQL
31+
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc = false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--- alter_statistics.sql
2+
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
3+
--- AST
4+
&ast.AlterStatistics{
5+
Alter: 0,
6+
Name: &ast.Ident{
7+
NamePos: 17,
8+
NameEnd: 42,
9+
Name: "auto_20191128_14_47_22UTC",
10+
},
11+
Options: &ast.Options{
12+
Options: 47,
13+
Rparen: 70,
14+
Records: []*ast.OptionsDef{
15+
&ast.OptionsDef{
16+
Name: &ast.Ident{
17+
NamePos: 56,
18+
NameEnd: 64,
19+
Name: "allow_gc",
20+
},
21+
Value: &ast.BoolLiteral{
22+
ValuePos: 65,
23+
Value: false,
24+
},
25+
},
26+
},
27+
},
28+
}
29+
30+
--- SQL
31+
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc = false)

0 commit comments

Comments
 (0)