Skip to content

Commit

Permalink
put pk in indices and revert test
Browse files Browse the repository at this point in the history
  • Loading branch information
WangXiangUSTC committed Dec 11, 2019
1 parent b8a36f1 commit 157d14e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/dbutil/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (*testDBSuite) TestIndex(c *C) {
PRIMARY KEY (a)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
`,
[]string{"b", "c"},
[]string{"b", "c"},
[]string{"PRIMARY", "b", "c"},
[]string{"a", "b", "c"},
}, {
`
CREATE TABLE mtest (
Expand Down
16 changes: 16 additions & 0 deletions pkg/dbutil/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ func GetTableInfoBySQL(createTableSQL string, sqlMode string) (table *model.Tabl
if err != nil {
return nil, errors.Trace(err)
}

// put primary key in indices
if table.PKIsHandle {
pkIndex := &model.IndexInfo{
Name: model.NewCIStr("PRIMARY"),
Primary: true,
Columns: []*model.IndexColumn{
{
Name: table.GetPkName(),
},
},
}

table.Indices = append(table.Indices, pkIndex)
}

return table, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/diff/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *testUtilSuite) TestIgnoreColumns(c *C) {
c.Assert(err, IsNil)
tbInfo = ignoreColumns(tableInfo3, []string{"b", "c"})
c.Assert(tbInfo.Columns, HasLen, 2)
c.Assert(tbInfo.Indices, HasLen, 0)
c.Assert(tbInfo.Indices, HasLen, 1)
}

func (s *testUtilSuite) TestRowContainsCols(c *C) {
Expand Down

0 comments on commit 157d14e

Please sign in to comment.