Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: display 'show create table' and INFOSCHEMA for cached table correctly #30951

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(""))
}