Skip to content

Commit

Permalink
*: Add support "show open tables"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
july2993 committed Apr 17, 2019
1 parent 44cbb23 commit 8ebdd43
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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:
Expand Down Expand Up @@ -242,6 +244,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 {
checker := privilege.GetPrivilegeManager(e.ctx)
if checker != nil && e.ctx.GetSessionVars().User != nil && !checker.DBIsVisible(e.DBName.O) {
Expand Down
6 changes: 6 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ func (s *testSuite2) TestShowSlow(c *C) {
tk.MustQuery(`admin show slow top all 3`)
}

func (s *testSuite2) TestShowOpenTables(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustQuery("show open tables")
tk.MustQuery("show open tables in test")
}

func (s *testSuite2) TestShowCreateTable(c *C) {
tk := testkit.NewTestKit(c, s.store)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e
github.com/pingcap/kvproto v0.0.0-20190215154024-7f2fc73ef562
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596
github.com/pingcap/parser v0.0.0-20190409044748-a0b301443a30
github.com/pingcap/parser v0.0.0-20190417034638-5dc3d0b90fd1
github.com/pingcap/pd v2.1.0-rc.4+incompatible
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible
github.com/pingcap/tipb v0.0.0-20190107072121-abbec73437b7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/pingcap/kvproto v0.0.0-20190215154024-7f2fc73ef562 h1:32oF1/8lVnBR2JV
github.com/pingcap/kvproto v0.0.0-20190215154024-7f2fc73ef562/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY=
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-20190409044748-a0b301443a30 h1:Cu+VJBHLUqI0TFj/0Kya4L1iHIJZ3VbtZcEwv+3zOxQ=
github.com/pingcap/parser v0.0.0-20190409044748-a0b301443a30/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20190417034638-5dc3d0b90fd1 h1:VxaDtE1SZ7WEBLLSQynqs4q9hInIZ+AbcfT17qjKneo=
github.com/pingcap/parser v0.0.0-20190417034638-5dc3d0b90fd1/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.20190321065848-1e8b48f5c168+incompatible h1:MkWCxgZpJBgY2f4HtwWMMFzSBb3+JPzeJgF3VrXE/bU=
Expand Down
3 changes: 3 additions & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,9 @@ func buildShowSchema(s *ast.ShowStmt, isView bool) (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 {
Expand Down

0 comments on commit 8ebdd43

Please sign in to comment.