Skip to content

Commit

Permalink
*: fix auto increment type (pingcap#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed May 26, 2016
1 parent 86fe54d commit c9413d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ func (d *ddl) buildTableInfo(tableName model.CIStr, cols []*table.Column, constr
return nil, infoschema.ErrColumnNotExists.Gen("no such column: %v", key)
}
switch col.Tp {
case mysql.TypeLong, mysql.TypeLonglong:
case mysql.TypeLong, mysql.TypeLonglong,
mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24:
tbInfo.PKIsHandle = true
// Avoid creating index for PK handle column.
continue
Expand Down
8 changes: 7 additions & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func (s *testSessionSuite) TestAutoIncrementID(c *C) {
defer testleak.AfterTest(c)()
store := newStore(c, s.dbName)
se := newSession(c, store, s.dbName)

mustExecSQL(c, se, "drop table if exists t")
mustExecSQL(c, se, "create table t (id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL)")
mustExecSQL(c, se, "insert t values ()")
Expand All @@ -253,8 +254,13 @@ func (s *testSessionSuite) TestAutoIncrementID(c *C) {
mustExecSQL(c, se, "insert t () values ()")
c.Assert(se.LastInsertID(), Greater, lastID)
mustExecSQL(c, se, "insert t () select 100")
mustExecSQL(c, se, s.dropDBSQL)

mustExecSQL(c, se, "drop table if exists t")
mustExecSQL(c, se, "create table t (i tinyint unsigned not null auto_increment, primary key (i));")
mustExecSQL(c, se, "insert into t set i = 254;")
mustExecSQL(c, se, "insert t values ()")

mustExecSQL(c, se, s.dropDBSQL)
err := store.Close()
c.Assert(err, IsNil)
}
Expand Down

0 comments on commit c9413d6

Please sign in to comment.