From 64c77b42f1960b50155632c041e0d07561cc28c9 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Tue, 19 Sep 2023 15:57:13 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #47078 Signed-off-by: ti-chi-bot --- planner/core/integration_test.go | 15 +++++++++++++++ planner/core/rule_inject_extra_projection.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 83e464f31ec3c..5afbc96f03c27 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -1899,6 +1899,7 @@ func TestINLJHintSmallTable(t *testing.T) { tk.MustExec("explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a") } +<<<<<<< HEAD func TestIndexJoinUniqueCompositeIndex(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1975,6 +1976,20 @@ func TestIndexMergeHint4CNF(t *testing.T) { }) tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) } +======= +func TestIssue46580(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`CREATE TABLE t0(c0 INT);`) + tk.MustExec(`CREATE TABLE t1(c0 BOOL, c1 BOOL);`) + tk.MustExec(`INSERT INTO t1 VALUES (false, true);`) + tk.MustExec(`INSERT INTO t1 VALUES (true, true);`) + tk.MustExec(`CREATE definer='root'@'localhost' VIEW v0(c0, c1, c2) AS SELECT t1.c0, LOG10(t0.c0), t1.c0 FROM t0, t1;`) + tk.MustExec(`INSERT INTO t0(c0) VALUES (3);`) + tk.MustQuery(`SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1;`).Sort().Check( + testkit.Rows(`0 0`, `0 1`, `1 0`, `1 1`)) +>>>>>>> 51f6bb90d98 (planner: fix Uncertain Results caused by MERGE_JOIN (#47078)) } func TestInvisibleIndex(t *testing.T) { diff --git a/planner/core/rule_inject_extra_projection.go b/planner/core/rule_inject_extra_projection.go index 308584b0bc1c9..9f2c13593394b 100644 --- a/planner/core/rule_inject_extra_projection.go +++ b/planner/core/rule_inject_extra_projection.go @@ -275,6 +275,7 @@ func InjectProjBelowSort(p PhysicalPlan, orderByItems []*util.ByItems) PhysicalP if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj { refine4NeighbourProj(bottomProj, origChildProj) } + refine4NeighbourProj(topProj, bottomProj) return topProj } @@ -336,6 +337,7 @@ func TurnNominalSortIntoProj(p PhysicalPlan, onlyColumn bool, orderByItems []*ut if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj { refine4NeighbourProj(bottomProj, origChildProj) } + refine4NeighbourProj(topProj, bottomProj) return topProj } From 3d944e111cb633885943731dcaef44eb249dace8 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 19 Oct 2023 15:51:19 +0800 Subject: [PATCH 2/3] fixup --- planner/core/integration_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 5afbc96f03c27..b29c3099d3ebd 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -1899,7 +1899,6 @@ func TestINLJHintSmallTable(t *testing.T) { tk.MustExec("explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a") } -<<<<<<< HEAD func TestIndexJoinUniqueCompositeIndex(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1963,7 +1962,7 @@ func TestIndexMergeHint4CNF(t *testing.T) { tk.MustExec("create table t(id int primary key, a int, b int, c int, key(a), key(b), key(c))") var input []string - var output []struct { + var output[]struct { SQL string Plan []string } @@ -1976,8 +1975,9 @@ func TestIndexMergeHint4CNF(t *testing.T) { }) tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...)) } -======= -func TestIssue46580(t *testing.T) { +} + + func TestIssue46580(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") @@ -1989,7 +1989,6 @@ func TestIssue46580(t *testing.T) { tk.MustExec(`INSERT INTO t0(c0) VALUES (3);`) tk.MustQuery(`SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1;`).Sort().Check( testkit.Rows(`0 0`, `0 1`, `1 0`, `1 1`)) ->>>>>>> 51f6bb90d98 (planner: fix Uncertain Results caused by MERGE_JOIN (#47078)) } func TestInvisibleIndex(t *testing.T) { From 2ba20c8158224a76214dc1c14ec460fc329aba2f Mon Sep 17 00:00:00 2001 From: qw4990 Date: Thu, 19 Oct 2023 15:51:27 +0800 Subject: [PATCH 3/3] fixup --- planner/core/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b29c3099d3ebd..b3ff896471804 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -1962,7 +1962,7 @@ func TestIndexMergeHint4CNF(t *testing.T) { tk.MustExec("create table t(id int primary key, a int, b int, c int, key(a), key(b), key(c))") var input []string - var output[]struct { + var output []struct { SQL string Plan []string } @@ -1977,7 +1977,7 @@ func TestIndexMergeHint4CNF(t *testing.T) { } } - func TestIssue46580(t *testing.T) { +func TestIssue46580(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test")