From ce3f45544cfffe05620e9fe7b58b2e28cd2508b8 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Tue, 19 Sep 2023 15:16:50 +0800 Subject: [PATCH 1/2] fixup --- planner/core/rule_inject_extra_projection.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/planner/core/rule_inject_extra_projection.go b/planner/core/rule_inject_extra_projection.go index 9d5f86e41c0f6..6b7940ec6bf4d 100644 --- a/planner/core/rule_inject_extra_projection.go +++ b/planner/core/rule_inject_extra_projection.go @@ -264,6 +264,7 @@ func InjectProjBelowSort(p PhysicalPlan, orderByItems []*util.ByItems) PhysicalP if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj { refine4NeighbourProj(bottomProj, origChildProj) } + refine4NeighbourProj(topProj, bottomProj) return topProj } @@ -325,6 +326,7 @@ func TurnNominalSortIntoProj(p PhysicalPlan, onlyColumn bool, orderByItems []*ut if origChildProj, isChildProj := childPlan.(*PhysicalProjection); isChildProj { refine4NeighbourProj(bottomProj, origChildProj) } + refine4NeighbourProj(topProj, bottomProj) return topProj } From b0ed9338cce33e98d5c401a27588838f467e4e81 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Tue, 19 Sep 2023 15:21:39 +0800 Subject: [PATCH 2/2] fixup --- planner/core/integration_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index b667281a4a0ca..1582321163233 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -619,6 +619,20 @@ func TestINLJHintSmallTable(t *testing.T) { tk.MustExec("explain format = 'brief' select /*+ TIDB_INLJ(t1) */ * from t1 join t2 on t1.a = t2.a") } +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`)) +} + func TestInvisibleIndex(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store)