diff --git a/ast/ddl.go b/ast/ddl.go index 20f75f300..ab53f259c 100644 --- a/ast/ddl.go +++ b/ast/ddl.go @@ -156,7 +156,13 @@ type IndexColName struct { // Restore implements Node interface. func (n *IndexColName) Restore(ctx *RestoreCtx) error { - return errors.New("Not implemented") + if err := n.Column.Restore(ctx); err != nil { + return errors.Annotate(err, "An error occurred while splicing IndexColName") + } + if n.Length > 0 { + ctx.WritePlainf("(%d)", n.Length) + } + return nil } // Accept implements Node Accept interface. diff --git a/ast/ddl_test.go b/ast/ddl_test.go index 08fe6173f..079bdd818 100644 --- a/ast/ddl_test.go +++ b/ast/ddl_test.go @@ -63,6 +63,17 @@ func (ts *testDDLSuite) TestDDLVisitorCover(c *C) { } } +func (ts *testDDLSuite) TestDDLIndexColNameRestore(c *C) { + testCases := []NodeRestoreTestCase{ + {"world", "`world`"}, + {"world(2)", "`world`(2)"}, + } + extractNodeFunc := func(node Node) Node { + return node.(*CreateIndexStmt).IndexColNames[0] + } + RunNodeRestoreTest(c, testCases, "CREATE INDEX idx ON t (%s) USING HASH", extractNodeFunc) +} + func (ts *testDDLSuite) TestDDLOnDeleteRestore(c *C) { testCases := []NodeRestoreTestCase{ {"on delete restrict", "ON DELETE RESTRICT"},