Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 committed Jun 3, 2021
1 parent 90c3e3d commit 0bea1b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5360,11 +5360,11 @@ func (s *testSerialDBSuite) TestSetTiFlashReplicaForTemporaryTable(c *C) {
tk.MustExec("alter table normal set tiflash replica 1")
tk.MustQuery("select REPLICA_COUNT from information_schema.tiflash_replica where table_schema='test' and table_name='normal'").Check(testkit.Rows("1"))
tk.MustExec("create global temporary table temp like normal on commit delete rows")
tk.MustQuery("select REPLICA_COUNT from information_schema.tiflash_replica where table_schema='test' and table_name='temp'").Check(testkit.Rows("0"))
tk.MustQuery("select REPLICA_COUNT from information_schema.tiflash_replica where table_schema='test' and table_name='temp'").Check(testkit.Rows())
tk.MustExec("drop table temp")
tk.MustExec("set tidb_enable_noop_functions = 1")
tk.MustExec("create temporary table temp like normal")
tk.MustQuery("select REPLICA_COUNT from information_schema.tiflash_replica where table_schema='test' and table_name='temp'").Check(testkit.Rows("0"))
tk.MustQuery("select REPLICA_COUNT from information_schema.tiflash_replica where table_schema='test' and table_name='temp'").Check(testkit.Rows())
}

func (s *testSerialDBSuite) TestAlterShardRowIDBits(c *C) {
Expand Down
8 changes: 5 additions & 3 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ func checkTableInfoValid(tblInfo *model.TableInfo) error {
return checkInvisibleIndexOnPK(tblInfo)
}

func buildTableInfoWithLike(ident ast.Ident, referTblInfo *model.TableInfo) (*model.TableInfo, error) {
func buildTableInfoWithLike(ident ast.Ident, referTblInfo *model.TableInfo, s *ast.CreateTableStmt) (*model.TableInfo, error) {
// Check the referred table is a real table object.
if referTblInfo.IsSequence() || referTblInfo.IsView() {
return nil, ErrWrongObject.GenWithStackByArgs(ident.Schema, referTblInfo.Name, "BASE TABLE")
Expand All @@ -1663,7 +1663,9 @@ func buildTableInfoWithLike(ident ast.Ident, referTblInfo *model.TableInfo) (*mo
tblInfo.AutoIncID = 0
tblInfo.ForeignKeys = nil
// Ignore TiFlash replicas for temporary tables.
if tblInfo.TiFlashReplica != nil && tblInfo.TempTableType == model.TempTableNone {
if s.TemporaryKeyword != ast.TemporaryNone {
tblInfo.TiFlashReplica = nil
} else if tblInfo.TiFlashReplica != nil {
replica := *tblInfo.TiFlashReplica
// Keep the tiflash replica setting, remove the replica available status.
replica.AvailablePartitionIDs = nil
Expand Down Expand Up @@ -1811,7 +1813,7 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
// build tableInfo
var tbInfo *model.TableInfo
if s.ReferTable != nil {
tbInfo, err = buildTableInfoWithLike(ident, referTbl.Meta())
tbInfo, err = buildTableInfoWithLike(ident, referTbl.Meta(), s)
} else {
tbInfo, err = buildTableInfoWithStmt(ctx, s, schema.Charset, schema.Collate)
}
Expand Down

0 comments on commit 0bea1b1

Please sign in to comment.