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 issue that TIDB_INLJ hint cannot take effect when left joining two sub-queries #46271

Merged
merged 3 commits into from
Aug 21, 2023
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
13 changes: 13 additions & 0 deletions planner/core/casetest/hint/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,16 @@ func TestInvalidHint(t *testing.T) {
tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...))
}
}

func TestIssue46160(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

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")
}
3 changes: 2 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,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