From 76c806ef6fd22ef34da76c1211cfa92d1fa0e330 Mon Sep 17 00:00:00 2001 From: Kenan Yao Date: Tue, 31 Mar 2020 20:45:11 +0800 Subject: [PATCH 1/2] cherry pick #15840 to release-3.1 Signed-off-by: sre-bot --- planner/core/exhaust_physical_plans.go | 2 +- planner/core/integration_test.go | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 68b2ca8a30c29..c29d84ca3920f 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -81,7 +81,7 @@ func (p *LogicalJoin) moveEqualToOtherConditions(offsets []int) []expression.Exp // Construct otherConds, which is composed of the original other conditions // and the remained unused equal conditions. - numOtherConds := len(p.OtherConditions) + len(p.EqualConditions) - len(offsets) + numOtherConds := len(p.OtherConditions) + len(p.EqualConditions) - len(usedEqConds) otherConds := make([]expression.Expression, len(p.OtherConditions), numOtherConds) copy(otherConds, p.OtherConditions) for eqCondIdx := range p.EqualConditions { diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index faa69253e4caa..7c47a3a53790a 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -558,6 +558,55 @@ func (s *testIntegrationSuite) TestIssue15546(c *C) { tk.MustExec("create table pt(a2 int primary key, b2 int) partition by range(a2) (" + "PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30))") tk.MustExec("insert into pt values(1, 1), (11, 11), (21, 21)") +<<<<<<< HEAD tk.MustExec("create definer='root'@'localhost' view vt(a1, b1) as select a1, b1 from t") tk.MustQuery("select * from pt, vt where a2 = a1").Check(testkit.Rows("1 1 1 1")) +======= + tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") + tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) +} + +func (s *testIntegrationSuite) TestIssue15813(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t0, t1") + tk.MustExec("create table t0(c0 int primary key)") + tk.MustExec("create table t1(c0 int primary key)") + tk.MustExec("CREATE INDEX i0 ON t0(c0)") + tk.MustExec("CREATE INDEX i0 ON t1(c0)") + tk.MustQuery("select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0").Check(testkit.Rows()) +} + +func (s *testIntegrationSuite) TestHintWithoutTableWarning(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1, t2") + tk.MustExec("create table t1(a int, b int, c int, key a(a))") + tk.MustExec("create table t2(a int, b int, c int, key a(a))") + var input []string + var output []struct { + SQL string + Warnings []string + } + s.testData.GetTestCases(c, &input, &output) + for i, tt := range input { + s.testData.OnRecord(func() { + output[i].SQL = tt + tk.MustQuery(tt) + warns := tk.Se.GetSessionVars().StmtCtx.GetWarnings() + output[i].Warnings = make([]string, len(warns)) + for j := range warns { + output[i].Warnings[j] = warns[j].Err.Error() + } + }) + tk.MustQuery(tt) + warns := tk.Se.GetSessionVars().StmtCtx.GetWarnings() + c.Assert(len(warns), Equals, len(output[i].Warnings)) + for j := range warns { + c.Assert(warns[j].Level, Equals, stmtctx.WarnLevelWarning) + c.Assert(warns[j].Err.Error(), Equals, output[i].Warnings[j]) + } + } +>>>>>>> 10de222... planner: fix panic of merge join for tables with redundant indexes (#15840) } From dfc078e00955b307cd8c1e7ae2635e4b2fd93c9e Mon Sep 17 00:00:00 2001 From: Kenan Yao Date: Sat, 28 Mar 2020 04:39:39 +0800 Subject: [PATCH 2/2] resolve conflicts --- planner/core/integration_test.go | 37 -------------------------------- 1 file changed, 37 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 7c47a3a53790a..e40d0a0f92591 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -558,12 +558,8 @@ func (s *testIntegrationSuite) TestIssue15546(c *C) { tk.MustExec("create table pt(a2 int primary key, b2 int) partition by range(a2) (" + "PARTITION `p0` VALUES LESS THAN (10), PARTITION `p1` VALUES LESS THAN (20), PARTITION `p2` VALUES LESS THAN (30))") tk.MustExec("insert into pt values(1, 1), (11, 11), (21, 21)") -<<<<<<< HEAD tk.MustExec("create definer='root'@'localhost' view vt(a1, b1) as select a1, b1 from t") tk.MustQuery("select * from pt, vt where a2 = a1").Check(testkit.Rows("1 1 1 1")) -======= - tk.MustExec("create definer='root'@'localhost' view vt(a, b) as select a, b from t") - tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1")) } func (s *testIntegrationSuite) TestIssue15813(c *C) { @@ -577,36 +573,3 @@ func (s *testIntegrationSuite) TestIssue15813(c *C) { tk.MustExec("CREATE INDEX i0 ON t1(c0)") tk.MustQuery("select /*+ MERGE_JOIN(t0, t1) */ * from t0, t1 where t0.c0 = t1.c0").Check(testkit.Rows()) } - -func (s *testIntegrationSuite) TestHintWithoutTableWarning(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int, b int, c int, key a(a))") - tk.MustExec("create table t2(a int, b int, c int, key a(a))") - var input []string - var output []struct { - SQL string - Warnings []string - } - s.testData.GetTestCases(c, &input, &output) - for i, tt := range input { - s.testData.OnRecord(func() { - output[i].SQL = tt - tk.MustQuery(tt) - warns := tk.Se.GetSessionVars().StmtCtx.GetWarnings() - output[i].Warnings = make([]string, len(warns)) - for j := range warns { - output[i].Warnings[j] = warns[j].Err.Error() - } - }) - tk.MustQuery(tt) - warns := tk.Se.GetSessionVars().StmtCtx.GetWarnings() - c.Assert(len(warns), Equals, len(output[i].Warnings)) - for j := range warns { - c.Assert(warns[j].Level, Equals, stmtctx.WarnLevelWarning) - c.Assert(warns[j].Err.Error(), Equals, output[i].Warnings[j]) - } - } ->>>>>>> 10de222... planner: fix panic of merge join for tables with redundant indexes (#15840) -}