Skip to content

Commit

Permalink
Add DDL parser for "CHECK TABLE" statement (#21)
Browse files Browse the repository at this point in the history
* Update 2022/11/13

* Update 2022/11/13

* Add DDL parser for "CHECK TABLE" statement
  • Loading branch information
DemanWei authored Jan 12, 2023
1 parent 54605cb commit 83d40be
Show file tree
Hide file tree
Showing 5 changed files with 5,125 additions and 5,065 deletions.
37 changes: 37 additions & 0 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
_ DDLNode = &TruncateTableStmt{}
_ DDLNode = &RepairTableStmt{}
_ DDLNode = &OptimizeTableStmt{}
_ DDLNode = &CheckTableStmt{}

_ Node = &AlterTableSpec{}
_ Node = &ColumnDef{}
Expand Down Expand Up @@ -1944,6 +1945,42 @@ func (n *OptimizeTableStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// CheckTableStmt is a statement that checks a table or tables for errors
// See https://dev.mysql.com/doc/refman/8.0/en/check-table.html
type CheckTableStmt struct {
ddlNode
Tables []*TableName
}

func (c *CheckTableStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("CHECK TABLE ")
for i, v := range c.Tables {
if i != 0 {
ctx.WritePlain(", ")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore CheckTableStmt.Tables[%d]", i)
}
}
return nil
}

func (c *CheckTableStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(c)
if skipChildren {
return v.Leave(newNode)
}
c = newNode.(*CheckTableStmt)
for i := range c.Tables {
node, ok := c.Tables[i].Accept(v)
if !ok {
return c, false
}
c.Tables[i] = node.(*TableName)
}
return v.Leave(c)
}

// RepairTableStmt is a statement to repair tableInfo.
type RepairTableStmt struct {
ddlNode
Expand Down
1 change: 1 addition & 0 deletions ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestDDLVisitorCover(t *testing.T) {
{&DropIndexStmt{Table: &TableName{}}, 0, 0},
{&DropTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
{&OptimizeTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
{&CheckTableStmt{Tables: []*TableName{{}, {}}}, 0, 0},
{&RenameTableStmt{TableToTables: []*TableToTable{}}, 0, 0},
{&TruncateTableStmt{Table: &TableName{}}, 0, 0},

Expand Down
Loading

0 comments on commit 83d40be

Please sign in to comment.