Skip to content

Commit

Permalink
cherry pick pingcap#27798 to release-5.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
time-and-fate authored and ti-srebot committed Sep 6, 2021
1 parent f0b0834 commit 0015719
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
71 changes: 71 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3724,3 +3724,74 @@ func (s *testIntegrationSuite) TestGroupBySetVar(c *C) {
res.Check(testkit.Rows(output[i].Plan...))
}
}
<<<<<<< HEAD
=======

func (s *testIntegrationSerialSuite) TestPushDownGroupConcatToTiFlash(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists ts")
tk.MustExec("create table ts (col_0 char(64), col_1 varchar(64) not null, col_2 varchar(1), id int primary key);")

// Create virtual tiflash replica info.
dom := domain.GetDomain(tk.Se)
is := dom.InfoSchema()
db, exists := is.SchemaByName(model.NewCIStr("test"))
c.Assert(exists, IsTrue)
for _, tblInfo := range db.Tables {
if tblInfo.Name.L == "ts" {
tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{
Count: 1,
Available: true,
}
}
}

tk.MustExec("set @@tidb_isolation_read_engines='tiflash,tidb'; set @@tidb_allow_mpp=1; set @@tidb_enforce_mpp=1;")

var input []string
var output []struct {
SQL string
Plan []string
}
s.testData.GetTestCases(c, &input, &output)
for i, tt := range input {
s.testData.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
})
res := tk.MustQuery(tt)
res.Check(testkit.Rows(output[i].Plan...))
}
}

func (s *testIntegrationSuite) TestIssue27797(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t27797")
tk.MustExec("create table t27797(a int, b int, c int, d int) " +
"partition by range columns(d) (" +
"partition p0 values less than (20)," +
"partition p1 values less than(40)," +
"partition p2 values less than(60));")
tk.MustExec("insert into t27797 values(1,1,1,1), (2,2,2,2), (22,22,22,22), (44,44,44,44);")
tk.MustExec("set sql_mode='';")
result := tk.MustQuery("select count(*) from (select a, b from t27797 where d > 1 and d < 60 and b > 0 group by b, c) tt;")
result.Check(testkit.Rows("3"))

tk.MustExec("drop table if exists IDT_HP24172")
tk.MustExec("CREATE TABLE `IDT_HP24172` ( " +
"`COL1` mediumint(16) DEFAULT NULL, " +
"`COL2` varchar(20) DEFAULT NULL, " +
"`COL4` datetime DEFAULT NULL, " +
"`COL3` bigint(20) DEFAULT NULL, " +
"`COL5` float DEFAULT NULL, " +
"KEY `UM_COL` (`COL1`,`COL3`) " +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin " +
"PARTITION BY HASH( `COL1`+`COL3` ) " +
"PARTITIONS 8;")
tk.MustExec("insert into IDT_HP24172(col1) values(8388607);")
result = tk.MustQuery("select col2 from IDT_HP24172 where col1 = 8388607 and col1 in (select col1 from IDT_HP24172);")
result.Check(testkit.Rows("<nil>"))
}
>>>>>>> 68e32bb44... planner: fix wrong plan caused by shallow copy schema columns (#27798)
2 changes: 1 addition & 1 deletion planner/core/rule_aggregation_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (a *aggregationPushDownSolver) tryAggPushDownForUnion(union *LogicalUnionAl
}
newChildren = append(newChildren, newChild)
}
union.SetSchema(expression.NewSchema(newChildren[0].Schema().Columns...))
union.SetSchema(expression.NewSchema(newChildren[0].Schema().Clone().Columns...))
union.SetChildren(newChildren...)
return nil
}
Expand Down

0 comments on commit 0015719

Please sign in to comment.