diff --git a/table/tables/tables_test.go b/table/tables/tables_test.go index af94704355cc2..5b446b497e8cf 100644 --- a/table/tables/tables_test.go +++ b/table/tables/tables_test.go @@ -21,7 +21,9 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/errors" + "github.com/pingcap/parser/auth" "github.com/pingcap/parser/model" + "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -670,3 +672,34 @@ func (ts *testSuite) TestConstraintCheckForUniqueIndex(c *C) { // The data in channel is 1 means tk2 is blocked, that's the expected behavior. c.Assert(<-ch, Equals, 1) } + +func (ts *testSuite) TestViewColumns(c *C) { + se, err := session.CreateSession4Test(ts.store) + c.Assert(err, IsNil) + c.Assert(se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil), IsTrue) + tk := testkit.NewTestKitWithSession(c, ts.store, se) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int primary key, b varchar(20))") + tk.MustExec("drop view if exists v") + tk.MustExec("create view v as select * from t") + tk.MustExec("drop view if exists va") + tk.MustExec("create view va as select count(a) from t") + testCases := []struct { + query string + expected []string + }{ + {"select data_type from INFORMATION_SCHEMA.columns where table_name = 'v'", []string{types.TypeToStr(mysql.TypeLong, ""), types.TypeToStr(mysql.TypeVarchar, "")}}, + {"select data_type from INFORMATION_SCHEMA.columns where table_name = 'va'", []string{types.TypeToStr(mysql.TypeLonglong, "")}}, + } + for _, testCase := range testCases { + tk.MustQuery(testCase.query).Check(testutil.RowsWithSep("|", testCase.expected...)) + } + tk.MustExec("drop table if exists t") + for _, testCase := range testCases { + c.Assert(tk.MustQuery(testCase.query).Rows(), HasLen, 0) + tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", + "Warning|1356|View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them", + "Warning|1356|View 'test.va' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them")) + } +}