Skip to content

Commit

Permalink
cherry pick pingcap#20992 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
eurekaka committed Nov 27, 2020
1 parent 0bcb1b5 commit 94f3dbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions planner/core/hints.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func getTableName(tblName model.CIStr, asName *model.CIStr) model.CIStr {
}

func extractTableAsName(p PhysicalPlan) (*model.CIStr, *model.CIStr) {
_, isProj := p.(*PhysicalProjection)
_, isUnionScan := p.(*PhysicalUnionScan)
if isProj || isUnionScan {
return extractTableAsName(p.Children()[0])
}
if len(p.Children()) > 1 {
return nil, nil
}
Expand Down
17 changes: 17 additions & 0 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,23 @@ func (s *testPlanSuite) TestAggregationHints(c *C) {
}
}

func (s *testPlanSuite) TestExplainJoinHints(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer func() {
dom.Close()
store.Close()
}()
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, c int, key(b), key(c))")
tk.MustQuery("explain format='hint' select /*+ inl_hash_join(t2) */ * from t t1 inner join t t2 on t1.b = t2.b and t1.c = 1").Check(testkit.Rows(
"use_index(@`sel_1` `test`.`t1` `c`), use_index(@`sel_1` `test`.`t2` `b`), inl_hash_join(@`sel_1` `test`.`t2`), inl_hash_join(`t2`)",
))
}

func (s *testPlanSuite) TestAggToCopHint(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
Expand Down

0 comments on commit 94f3dbb

Please sign in to comment.