From 55dc12f786691bee5d5efd34fd14c2986490c5ef Mon Sep 17 00:00:00 2001 From: Jiahao Huang Date: Fri, 19 Apr 2019 11:23:16 +0800 Subject: [PATCH 1/3] *: Add support "show open tables" (#10166) 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 --- executor/show.go | 8 ++++++++ executor/show_test.go | 7 ++++++- planner/core/planbuilder.go | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) 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/planner/core/planbuilder.go b/planner/core/planbuilder.go index 6ea53a28e9293..b1b06ba7134e2 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1623,6 +1623,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 { From 323854c107accdfce275c2a382fe918ac139c26c Mon Sep 17 00:00:00 2001 From: Lynn Date: Tue, 7 May 2019 13:44:28 +0800 Subject: [PATCH 2/3] *: pudate parser package --- go.mod | 2 ++ go.sum | 2 ++ 2 files changed, 4 insertions(+) diff --git a/go.mod b/go.mod index 23c407f104f0a..f64145191284b 100644 --- a/go.mod +++ b/go.mod @@ -78,3 +78,5 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect ) + +replace github.com/pingcap/parser => github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e diff --git a/go.sum b/go.sum index 592bae0edeb24..d65058f45c344 100644 --- a/go.sum +++ b/go.sum @@ -141,6 +141,8 @@ github.com/unrolled/render v0.0.0-20171102162132-65450fb6b2d3/go.mod h1:tu82oB5W github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= 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= From 3bd070d8f4b0b9c8637619da66f16632fd11a787 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 29 May 2019 15:58:50 +0800 Subject: [PATCH 3/3] *: update mod --- go.mod | 4 +--- go.sum | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f64145191284b..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-20190505094039-595d728571a7 + 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 @@ -78,5 +78,3 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.0.0 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect ) - -replace github.com/pingcap/parser => github.com/zimulala/parser v0.0.0-20190507040735-52f43e397b1e diff --git a/go.sum b/go.sum index d65058f45c344..c4452cb02b97a 100644 --- a/go.sum +++ b/go.sum @@ -103,6 +103,10 @@ github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3F github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= github.com/pingcap/parser v0.0.0-20190505094039-595d728571a7 h1:cbTQGLE0X69qL2nrvtG9HP4u5sBdVGyoIJOhc+KtJXc= github.com/pingcap/parser v0.0.0-20190505094039-595d728571a7/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190529063845-f64799cf0af3 h1:WS3YzSKVUfvAj8lGYmUuksEMquE01Xxv6O/23eLP/Pc= +github.com/pingcap/parser v0.0.0-20190529063845-f64799cf0af3/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=