diff --git a/executor/show.go b/executor/show.go index c82dd616a3076..3d6ee944cb14a 100644 --- a/executor/show.go +++ b/executor/show.go @@ -130,6 +130,8 @@ func (e *ShowExec) fetchAll() error { return e.fetchShowStatus() case ast.ShowTables: return e.fetchShowTables() + case ast.ShowOpenTables: + return e.fetchShowOpenTables() case ast.ShowTableStatus: return e.fetchShowTableStatus() case ast.ShowTriggers: @@ -223,6 +225,12 @@ func (e *ShowExec) fetchShowProcessList() error { return nil } +func (e *ShowExec) fetchShowOpenTables() error { + // TiDB has no concept like mysql's "table cache" and "open table" + // For simplicity, we just return an empty result with the same structure as MySQL's SHOW OPEN TABLES + return nil +} + func (e *ShowExec) fetchShowTables() error { if !e.is.SchemaExists(e.DBName) { return errors.Errorf("Can not find DB: %s", e.DBName) diff --git a/executor/show_test.go b/executor/show_test.go index 73ad89a307c4e..39854e0c0bd10 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -730,6 +730,12 @@ func (s *testSuite) TestShowSlow(c *C) { tk.MustQuery(`admin show slow top all 3`) } +func (s *testSuite) TestShowOpenTables(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustQuery("show open tables") + tk.MustQuery("show open tables in test") +} + func (s *testSuite) TestShowCreateTable(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -742,7 +748,6 @@ func (s *testSuite) TestShowCreateTable(c *C) { " `ch2` varbinary(10) DEFAULT NULL\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) - } func (s *testSuite) TestShowEscape(c *C) { diff --git a/go.mod b/go.mod index 118ed5699612c..bd3c988faefc2 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030 github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11 github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 - github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d + github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad github.com/pingcap/pd v2.1.0-rc.4+incompatible github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93 diff --git a/go.sum b/go.sum index 638c9ebdf1ccc..faee5d6466ac7 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11 h1:e81flSfRbbMW5RU github.com/pingcap/kvproto v0.0.0-20190226063853-f6c0b7ffff11/go.mod h1:0gwbe1F2iBIjuQ9AH0DbQhL+Dpr5GofU8fgYyXk+ykk= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d h1:KfAKc8SCBXKtvuyqrncd2gpBSzudNJEtKEHR5lqu1BM= -github.com/pingcap/parser v0.0.0-20190516020405-361d2d4f774d/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad h1:XLVTXFsIYkKlV55mbBk84op/W67Cjh497d0zLt6jn/M= +github.com/pingcap/parser v0.0.0-20190529073816-0550d84c65ad/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v2.1.0-rc.4+incompatible h1:/buwGk04aHO5odk/+O8ZOXGs4qkUjYTJ2UpCJXna8NE= github.com/pingcap/pd v2.1.0-rc.4+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E= 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 github.com/unrolled/render v0.0.0-20171102162132-65450fb6b2d3/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE= +github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e h1:EfemAunuGpGitSTziAdQoQXJiSkGhoRxkgu/lFDXs8Y= +github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e/go.mod h1:G69sWhUqZ6QkeOjLFa/d9eJsBxH7Y/JhkqOyvz1gZ3M= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index b6bab0f1d8e6f..4a60f30dc71e9 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1638,6 +1638,9 @@ func buildShowSchema(s *ast.ShowStmt) (schema *expression.Schema) { names = []string{"Engine", "Support", "Comment", "Transactions", "XA", "Savepoints"} case ast.ShowDatabases: names = []string{"Database"} + case ast.ShowOpenTables: + names = []string{"Database", "Table", "In_use", "Name_locked"} + ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeLong} case ast.ShowTables: names = []string{fmt.Sprintf("Tables_in_%s", s.DBName)} if s.Full {