Skip to content

Commit 201a89b

Browse files
authored
*: Add support "show open tables" (#10166) (#10374)
1 parent 2086519 commit 201a89b

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

executor/show.go

+8
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ func (e *ShowExec) fetchAll() error {
130130
return e.fetchShowStatus()
131131
case ast.ShowTables:
132132
return e.fetchShowTables()
133+
case ast.ShowOpenTables:
134+
return e.fetchShowOpenTables()
133135
case ast.ShowTableStatus:
134136
return e.fetchShowTableStatus()
135137
case ast.ShowTriggers:
@@ -223,6 +225,12 @@ func (e *ShowExec) fetchShowProcessList() error {
223225
return nil
224226
}
225227

228+
func (e *ShowExec) fetchShowOpenTables() error {
229+
// TiDB has no concept like mysql's "table cache" and "open table"
230+
// For simplicity, we just return an empty result with the same structure as MySQL's SHOW OPEN TABLES
231+
return nil
232+
}
233+
226234
func (e *ShowExec) fetchShowTables() error {
227235
if !e.is.SchemaExists(e.DBName) {
228236
return errors.Errorf("Can not find DB: %s", e.DBName)

executor/show_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ func (s *testSuite) TestShowSlow(c *C) {
730730
tk.MustQuery(`admin show slow top all 3`)
731731
}
732732

733+
func (s *testSuite) TestShowOpenTables(c *C) {
734+
tk := testkit.NewTestKit(c, s.store)
735+
tk.MustQuery("show open tables")
736+
tk.MustQuery("show open tables in test")
737+
}
738+
733739
func (s *testSuite) TestShowCreateTable(c *C) {
734740
tk := testkit.NewTestKit(c, s.store)
735741
tk.MustExec("use test")
@@ -742,7 +748,6 @@ func (s *testSuite) TestShowCreateTable(c *C) {
742748
" `ch2` varbinary(10) DEFAULT NULL\n"+
743749
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
744750
))
745-
746751
}
747752

748753
func (s *testSuite) TestShowEscape(c *C) {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require (
4848
github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030
4949
github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11
5050
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596
51-
github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d
51+
github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad
5252
github.com/pingcap/pd v2.1.0-rc.4+incompatible
5353
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible
5454
github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11 h1:e81flSfRbbMW5RU
8282
github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk=
8383
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ=
8484
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
85-
github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d h1:KfAKc8SCBXKtvuyqrncd2gpBSzudNJEtKEHR5lqu1BM=
86-
github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
85+
github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad h1:XLVTXFsIYkKlV55mbBk84op/W67Cjh497d0zLt6jn/M=
86+
github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
8787
github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE=
8888
github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
8989
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible h1:e9Gi/LP9181HT3gBfSOeSBA+5JfemuE4aEAhqNgoE4k=
@@ -117,6 +117,8 @@ github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJ
117117
github.com/unrolled/render v0.0.0-20171102162132-65450fb6b2d3/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg=
118118
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
119119
github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE=
120+
github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e h1:EfemAunuGpGitSTziAdQoQXJiSkGhoRxkgu/lFDXs8Y=
121+
github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e/go.mod h1:G69sWhUqZ6QkeOjLFa/d9eJsBxH7Y/JhkqOyvz1gZ3M=
120122
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
121123
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
122124
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=

planner/core/planbuilder.go

+3
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ func buildShowSchema(s *ast.ShowStmt) (schema *expression.Schema) {
16381638
names = []string{"Engine", "Support", "Comment", "Transactions", "XA", "Savepoints"}
16391639
case ast.ShowDatabases:
16401640
names = []string{"Database"}
1641+
case ast.ShowOpenTables:
1642+
names = []string{"Database", "Table", "In_use", "Name_locked"}
1643+
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeLong}
16411644
case ast.ShowTables:
16421645
names = []string{fmt.Sprintf("Tables_in_%s", s.DBName)}
16431646
if s.Full {

0 commit comments

Comments
 (0)