Skip to content

Commit

Permalink
cherry pick #21213 to release-4.0 (#21380)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Kenan Yao <cauchy1992@gmail.com>
  • Loading branch information
ti-srebot and eurekaka authored Dec 23, 2020
1 parent a0a70da commit 7800681
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,17 @@ func (s *testIntegrationSerialSuite) TestIssue20710(c *C) {
}
}

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

tk.MustExec("use test")
c.Assert(tk.HasPlan("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2", "HashJoin"), IsTrue)
tk.MustQuery("select /*+ HASH_JOIN(@sel_1 t2) */ * FROM (select 1) t1 NATURAL LEFT JOIN (select 2) t2").Check(testkit.Rows(
"1 2",
))
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings(), HasLen, 0)
}

func (s *testIntegrationSuite) TestIssue10448(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
6 changes: 5 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ func extractTableAlias(p Plan, parentOffset int) *hintTableInfo {
if blockOffset != parentOffset && blockAsNames != nil && blockAsNames[blockOffset].TableName.L != "" {
blockOffset = parentOffset
}
return &hintTableInfo{dbName: firstName.DBName, tblName: firstName.TblName, selectOffset: blockOffset}
dbName := firstName.DBName
if dbName.L == "" {
dbName = model.NewCIStr(p.SCtx().GetSessionVars().CurrentDB)
}
return &hintTableInfo{dbName: dbName, tblName: firstName.TblName, selectOffset: blockOffset}
}
return nil
}
Expand Down

0 comments on commit 7800681

Please sign in to comment.