Skip to content

Commit 51f6bb9

Browse files
authored
planner: fix Uncertain Results caused by MERGE_JOIN (#47078)
close #46580
1 parent 789de8d commit 51f6bb9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

planner/core/integration_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,20 @@ func TestINLJHintSmallTable(t *testing.T) {
620620
tk.MustExec("explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a")
621621
}
622622

623+
func TestIssue46580(t *testing.T) {
624+
store := testkit.CreateMockStore(t)
625+
tk := testkit.NewTestKit(t, store)
626+
tk.MustExec("use test")
627+
tk.MustExec(`CREATE TABLE t0(c0 INT);`)
628+
tk.MustExec(`CREATE TABLE t1(c0 BOOL, c1 BOOL);`)
629+
tk.MustExec(`INSERT INTO t1 VALUES (false, true);`)
630+
tk.MustExec(`INSERT INTO t1 VALUES (true, true);`)
631+
tk.MustExec(`CREATE definer='root'@'localhost' VIEW v0(c0, c1, c2) AS SELECT t1.c0, LOG10(t0.c0), t1.c0 FROM t0, t1;`)
632+
tk.MustExec(`INSERT INTO t0(c0) VALUES (3);`)
633+
tk.MustQuery(`SELECT /*+ MERGE_JOIN(t1, t0, v0)*/v0.c2, t1.c0 FROM v0, t0 CROSS JOIN t1 ORDER BY -v0.c1;`).Sort().Check(
634+
testkit.Rows(`0 0`, `0 1`, `1 0`, `1 1`))
635+
}
636+
623637
func TestInvisibleIndex(t *testing.T) {
624638
store := testkit.CreateMockStore(t)
625639
tk := testkit.NewTestKit(t, store)

planner/core/rule_inject_extra_projection.go

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func InjectProjBelowSort(p PhysicalPlan, orderByItems []*util.ByItems) PhysicalP
264264
if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj {
265265
refine4NeighbourProj(bottomProj, origChildProj)
266266
}
267+
refine4NeighbourProj(topProj, bottomProj)
267268

268269
return topProj
269270
}
@@ -325,6 +326,7 @@ func TurnNominalSortIntoProj(p PhysicalPlan, onlyColumn bool, orderByItems []*ut
325326
if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj {
326327
refine4NeighbourProj(bottomProj, origChildProj)
327328
}
329+
refine4NeighbourProj(topProj, bottomProj)
328330

329331
return topProj
330332
}

0 commit comments

Comments
 (0)