Skip to content

Commit

Permalink
planner: Fix the 'Unknown column' error when select from view… (pingc…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 4, 2020
1 parent e86c9cc commit e00c1f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,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 @@ -2566,7 +2566,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

0 comments on commit e00c1f8

Please sign in to comment.