From 58952730d3d4fb40ad02b09d72cd8ee56301582d Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 21 Aug 2023 14:55:14 +0800 Subject: [PATCH 1/3] fixup --- planner/core/logical_plan_builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index b0216c1b7f320..86bc02b47ce38 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -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 } } From 8aaa96b03fedf6fde7faaf1bb42283e4928a7f86 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 21 Aug 2023 14:58:02 +0800 Subject: [PATCH 2/3] fixup --- planner/core/casetest/hint/hint_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/planner/core/casetest/hint/hint_test.go b/planner/core/casetest/hint/hint_test.go index 69f650a0a599f..a232019cf6267 100644 --- a/planner/core/casetest/hint/hint_test.go +++ b/planner/core/casetest/hint/hint_test.go @@ -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") +} From 19b47abe019014352539d90e97a1104924597abf Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 21 Aug 2023 15:07:29 +0800 Subject: [PATCH 3/3] fixup --- executor/index_lookup_join_test.go | 10 ++++++++++ planner/core/casetest/hint/hint_test.go | 13 ------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index 6b5d6e96bcc44..b3910fdd1a872 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -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) { diff --git a/planner/core/casetest/hint/hint_test.go b/planner/core/casetest/hint/hint_test.go index a232019cf6267..69f650a0a599f 100644 --- a/planner/core/casetest/hint/hint_test.go +++ b/planner/core/casetest/hint/hint_test.go @@ -647,16 +647,3 @@ 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") -}