Skip to content

Commit

Permalink
executor: display 'show create table' and INFOSCHEMA for cached table…
Browse files Browse the repository at this point in the history
… correctly (#30951)

close #30950
  • Loading branch information
tiancaiamao authored Dec 23, 2021
1 parent 7121bf0 commit d2ed2ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ func (e *memtableRetriever) setDataFromTables(ctx context.Context, sctx sessionc
if !table.IsView() {
if table.GetPartitionInfo() != nil {
createOptions = "partitioned"
} else if table.TableCacheStatusType == model.TableCacheStatusEnable {
createOptions = "cached=on"
}
var autoIncID interface{}
hasAutoIncID, _ := infoschema.HasAutoIncrementColumn(table)
Expand Down
6 changes: 6 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
fmt.Fprintf(buf, " /*T![placement] PLACEMENT POLICY=%s */", stringutil.Escape(tableInfo.PlacementPolicyRef.Name.String(), sqlMode))
}

if tableInfo.TableCacheStatusType == model.TableCacheStatusEnable {
// This is not meant to be understand by other components, so it's not written as /*T![cached] */
// For all external components, cached table is just a normal table.
fmt.Fprintf(buf, " /* CACHED ON */")
}

// add direct placement info here
appendDirectPlacementInfo(tableInfo.DirectPlacementOpts, buf)
// add partition info here.
Expand Down
21 changes: 21 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1674,3 +1674,24 @@ func (s *testSuite5) TestShowTemporaryTable(c *C) {
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2"
tk.MustQuery("show create table t7").Check(testkit.Rows("t7 " + expect))
}

func (s *testSuite5) TestShowCachedTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t1 (id int)")
tk.MustExec("alter table t1 cache")
tk.MustQuery("show create table t1").Check(
testkit.Rows("t1 CREATE TABLE `t1` (\n" +
" `id` int(11) DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /* CACHED ON */"))
tk.MustQuery("select create_options from information_schema.tables where table_schema = 'test' and table_name = 't1'").Check(
testkit.Rows("cached=on"))

tk.MustExec("alter table t1 nocache")
tk.MustQuery("show create table t1").Check(
testkit.Rows("t1 CREATE TABLE `t1` (\n" +
" `id` int(11) DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustQuery("select create_options from information_schema.tables where table_schema = 'test' and table_name = 't1'").Check(
testkit.Rows(""))
}

0 comments on commit d2ed2ae

Please sign in to comment.