Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: Fix the 'Unknown column' error when select from view in another database (#15621) #15866

Merged
merged 4 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,17 @@ func (s *testDBSuite4) TestChangeColumn(c *C) {
s.tk.MustExec("drop table t3")
}

func (s *testDBSuite7) TestSelectInViewFromAnotherDB(c *C) {
_, _ = s.s.Execute(context.Background(), "create database test_db2")
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)
s.tk.MustExec("create table t(a int)")
s.tk.MustExec("use test_db2")
s.tk.MustExec("create sql security invoker view v as select * from " + s.schemaName + ".t")
s.tk.MustExec("use " + s.schemaName)
s.tk.MustExec("select test_db2.v.a from test_db2.v")
}

func (s *testDBSuite) mustExec(c *C, query string, args ...interface{}) {
s.tk.MustExec(query, args...)
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2433,7 +2433,7 @@ func (b *PlanBuilder) buildProjUponView(ctx context.Context, dbName model.CIStr,
OrigTblName: col.OrigTblName,
ColName: columnInfo[i].Name,
OrigColName: origColName,
DBName: col.DBName,
DBName: dbName,
RetType: col.GetType(),
})
projExprs = append(projExprs, col)
Expand Down