Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ALTER STATISTICS statement #163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (Revoke) isStatement() {}
func (CreateSequence) isStatement() {}
func (AlterSequence) isStatement() {}
func (DropSequence) isStatement() {}
func (AlterStatistics) isStatement() {}
func (CreateVectorIndex) isStatement() {}
func (DropVectorIndex) isStatement() {}
func (Insert) isStatement() {}
Expand Down Expand Up @@ -287,6 +288,7 @@ func (Revoke) isDDL() {}
func (CreateSequence) isDDL() {}
func (AlterSequence) isDDL() {}
func (DropSequence) isDDL() {}
func (AlterStatistics) isDDL() {}
func (CreateVectorIndex) isDDL() {}
func (DropVectorIndex) isDDL() {}

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

// AlterStatistics is ALTER STATISTICS statement node.
//
// ALTER STATISTICS {{.Name | sql}} SET {{.Options | sql}}
type AlterStatistics struct {
// pos = Alter
// end = Options.end

Alter token.Pos // position of "ALTER" keyword

Name *Ident
Options *Options
}

// ================================================================================
//
// Types for Schema
Expand Down
3 changes: 3 additions & 0 deletions ast/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,9 @@ func (e *ExecutePrivilegeOnTableFunction) End() token.Pos { return e.Names[len(e
func (r *RolePrivilege) Pos() token.Pos { return r.Role }
func (r *RolePrivilege) End() token.Pos { return r.Names[len(r.Names)-1].End() }

func (s *AlterStatistics) Pos() token.Pos { return s.Alter }
func (s *AlterStatistics) End() token.Pos { return s.Options.End() }

// ================================================================================
//
// Types for Schema
Expand Down
4 changes: 4 additions & 0 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,10 @@ func (r *RolePrivilege) SQL() string {
return sql
}

func (s *AlterStatistics) SQL() string {
return "ALTER STATISTICS " + s.Name.SQL() + " SET " + s.Options.SQL()
}

// ================================================================================
//
// Types for Schema
Expand Down
15 changes: 15 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,8 @@ func (p *Parser) parseDDL() ast.DDL {
return p.parseAlterSequence(pos)
case p.Token.IsKeywordLike("CHANGE"):
return p.parseAlterChangeStream(pos)
case p.Token.IsKeywordLike("STATISTICS"):
return p.parseAlterStatistics(pos)
}
p.panicfAtToken(&p.Token, "expected pseudo keyword: TABLE, CHANGE, but: %s", p.Token.AsString)
case p.Token.IsKeywordLike("DROP"):
Expand Down Expand Up @@ -3408,6 +3410,19 @@ func (p *Parser) parseSchemaType() ast.SchemaType {
panic(p.errorfAtToken(&p.Token, "expected token: ARRAY, <ident>, but: %s", p.Token.Kind))
}

func (p *Parser) parseAlterStatistics(pos token.Pos) *ast.AlterStatistics {
p.expectKeywordLike("STATISTICS")
name := p.parseIdent()
p.expect("SET")
options := p.parseOptions()

return &ast.AlterStatistics{
Alter: pos,
Name: name,
Options: options,
}
}

var scalarSchemaTypes = []string{
"BOOL",
"INT64",
Expand Down
1 change: 1 addition & 0 deletions testdata/input/ddl/alter_statistics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
31 changes: 31 additions & 0 deletions testdata/result/ddl/alter_statistics.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--- alter_statistics.sql
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
--- AST
&ast.AlterStatistics{
Alter: 0,
Name: &ast.Ident{
NamePos: 17,
NameEnd: 42,
Name: "auto_20191128_14_47_22UTC",
},
Options: &ast.Options{
Options: 47,
Rparen: 70,
Records: []*ast.OptionsDef{
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 56,
NameEnd: 64,
Name: "allow_gc",
},
Value: &ast.BoolLiteral{
ValuePos: 65,
Value: false,
},
},
},
},
}

--- SQL
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc = false)
31 changes: 31 additions & 0 deletions testdata/result/statement/alter_statistics.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--- alter_statistics.sql
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc=false)
--- AST
&ast.AlterStatistics{
Alter: 0,
Name: &ast.Ident{
NamePos: 17,
NameEnd: 42,
Name: "auto_20191128_14_47_22UTC",
},
Options: &ast.Options{
Options: 47,
Rparen: 70,
Records: []*ast.OptionsDef{
&ast.OptionsDef{
Name: &ast.Ident{
NamePos: 56,
NameEnd: 64,
Name: "allow_gc",
},
Value: &ast.BoolLiteral{
ValuePos: 65,
Value: false,
},
},
},
},
}

--- SQL
ALTER STATISTICS auto_20191128_14_47_22UTC SET OPTIONS (allow_gc = false)
Loading