Skip to content

Commit

Permalink
planner: fix the issue that TIDB_INLJ hint cannot take effect when le…
Browse files Browse the repository at this point in the history
…ft joining two sub-queries (#46271) (#46291)

close #46160
  • Loading branch information
ti-chi-bot authored Oct 12, 2023
1 parent 470d554 commit b653cf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions executor/index_lookup_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ func TestInapplicableIndexJoinHint(t *testing.T) {
tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t1) */ is inapplicable`))
tk.MustQuery(`select /*+ INL_MERGE_JOIN(t2) */ * from t1 right join t2 on t1.a=t2.a;`).Check(testkit.Rows())
tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t2) */ is inapplicable`))

// Test for issues/46160
tk.MustExec(`drop table if exists t1, t2;`)
tk.MustExec("use test")
tk.MustExec(`create table t1 (a int, key(a))`)
tk.MustExec(`create table t2 (a int, key(a))`)

query := `select /*+ tidb_inlj(bb) */ aa.* from (select * from t1) as aa left join
(select t2.a, t2.a*2 as a2 from t2) as bb on aa.a=bb.a;`
tk.HasPlan(query, "IndexJoin")
}

func TestIndexJoinOverflow(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ func extractTableAlias(p Plan, parentOffset int) *hintTableInfo {
if len(p.OutputNames()) > 0 && p.OutputNames()[0].TblName.L != "" {
firstName := p.OutputNames()[0]
for _, name := range p.OutputNames() {
if name.TblName.L != firstName.TblName.L || name.DBName.L != firstName.DBName.L {
if name.TblName.L != firstName.TblName.L ||
(name.DBName.L != "" && firstName.DBName.L != "" && name.DBName.L != firstName.DBName.L) { // DBName can be nil, see #46160
return nil
}
}
Expand Down

0 comments on commit b653cf0

Please sign in to comment.