diff --git a/executor/show.go b/executor/show.go index d96f9970c0ea1..0b971837cb766 100644 --- a/executor/show.go +++ b/executor/show.go @@ -251,6 +251,7 @@ func (e *ShowExec) fetchShowTables() error { } // sort for tables var tableNames []string + var tableTypes = make(map[string]string) for _, v := range e.is.SchemaTables(e.DBName) { // Test with mysql.AllPrivMask means any privilege would be OK. // TODO: Should consider column privileges, which also make a table visible. @@ -258,13 +259,16 @@ func (e *ShowExec) fetchShowTables() error { continue } tableNames = append(tableNames, v.Meta().Name.O) + if v.Meta().IsView() { + tableTypes[v.Meta().Name.O] = "VIEW" + } else { + tableTypes[v.Meta().Name.O] = "BASE TABLE" + } } sort.Strings(tableNames) for _, v := range tableNames { if e.Full { - // TODO: support "VIEW" later if we have supported view feature. - // now, just use "BASE TABLE". - e.appendRow([]interface{}{v, "BASE TABLE"}) + e.appendRow([]interface{}{v, tableTypes[v]}) } else { e.appendRow([]interface{}{v}) } diff --git a/executor/show_test.go b/executor/show_test.go index c01bab225f687..89dba5b3f6af4 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -171,11 +171,12 @@ func (s *testSuite2) TestShow2(c *C) { tk.MustExec("drop table if exists t") tk.MustExec(`create table if not exists t (c int) comment '注释'`) + tk.MustExec("create or replace view v as select * from t") tk.MustQuery(`show columns from t`).Check(testutil.RowsWithSep(",", "c,int(11),YES,,,")) tk.MustQuery("show collation where Charset = 'utf8' and Collation = 'utf8_bin'").Check(testutil.RowsWithSep(",", "utf8_bin,utf8,83,,Yes,1")) - tk.MustQuery("show tables").Check(testkit.Rows("t")) - tk.MustQuery("show full tables").Check(testkit.Rows("t BASE TABLE")) + tk.MustQuery("show tables").Check(testkit.Rows("t", "v")) + tk.MustQuery("show full tables").Check(testkit.Rows("t BASE TABLE", "v VIEW")) ctx := tk.Se.(sessionctx.Context) is := domain.GetDomain(ctx).InfoSchema() tblInfo, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))