Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: prohibit StreamAgg with group keys for TiFlash (#39547) #39565

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,8 +1104,43 @@ func (s *tiflashTestSuite) TestAggPushDownCountStar(c *C) {
tk.MustQuery("select count(*) from c, o where c.c_id=o.c_id").Check(testkit.Rows("5"))
}

<<<<<<< HEAD:executor/tiflash_test.go
func (s *tiflashTestSuite) TestTiflashEmptyDynamicPruneResult(c *C) {
tk := testkit.NewTestKit(c, s.store)
=======
func TestGroupStreamAggOnTiFlash(t *testing.T) {
store := testkit.CreateMockStore(t, withMockTiFlash(2))
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("drop table if exists foo")
tk.MustExec("create table foo(a int, b int, c int, d int, primary key(a,b,c,d))")
tk.MustExec("alter table foo set tiflash replica 1")
tk.MustExec("insert into foo values(1,2,3,1),(1,2,3,6),(1,2,3,5)," +
"(1,2,3,2),(1,2,3,4),(1,2,3,7),(1,2,3,3),(1,2,3,0)")
tb := external.GetTableByName(t, tk, "test", "foo")
err := domain.GetDomain(tk.Session()).DDL().UpdateTableReplicaInfo(tk.Session(), tb.Meta().ID, true)
require.NoError(t, err)
tk.MustExec("set @@tidb_allow_mpp=0")
sql := "select a,b,c,count(*) from foo group by a,b,c order by a,b,c"
tk.MustQuery(sql).Check(testkit.Rows("1 2 3 8"))
rows := tk.MustQuery("explain " + sql).Rows()

for _, row := range rows {
resBuff := bytes.NewBufferString("")
fmt.Fprintf(resBuff, "%s\n", row)
res := resBuff.String()
// StreamAgg with group keys on TiFlash is not supported
if strings.Contains(res, "tiflash") {
require.NotContains(t, res, "StreamAgg")
}
}
}

func TestTiflashEmptyDynamicPruneResult(t *testing.T) {
store := testkit.CreateMockStore(t, withMockTiFlash(2))
tk := testkit.NewTestKit(t, store)
>>>>>>> 38b0ab7333 (planner: prohibit StreamAgg with group keys for TiFlash (#39547)):executor/tiflashtest/tiflash_test.go
tk.MustExec("use test;")
tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE `IDT_RP24833` ( `COL1` bigint(16) DEFAULT '15' COMMENT 'NUMERIC UNIQUE INDEX',\n `COL2` varchar(20) DEFAULT NULL,\n `COL4` datetime DEFAULT NULL,\n `COL3` bigint(20) DEFAULT NULL,\n `COL5` float DEFAULT NULL,\n KEY `UK_COL1` (`COL1`) /*!80000 INVISIBLE */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY RANGE ((`COL1`-57))\n(PARTITION `P0` VALUES LESS THAN (-3503857335115112215),\n PARTITION `P1` VALUES LESS THAN (-2987877108151063747),\n PARTITION `P2` VALUES LESS THAN (-1981049919102122710),\n PARTITION `P3` VALUES LESS THAN (-1635802972727465681),\n PARTITION `P4` VALUES LESS THAN (1186020639986357714),\n PARTITION `P5` VALUES LESS THAN (1220018677454711359),\n PARTITION `PMX` VALUES LESS THAN (MAXVALUE));")
Expand Down
8 changes: 6 additions & 2 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1962,8 +1962,12 @@ func (p *PhysicalStreamAgg) attach2Task(tasks ...task) task {
inputRows = t.count()
attachPlan2Task(p, t)
} else {
copTaskType := cop.getStoreType()
partialAgg, finalAgg := p.newPartialAggregate(copTaskType, false)
storeType := cop.getStoreType()
// TiFlash doesn't support Stream Aggregation
if storeType == kv.TiFlash && len(p.GroupByItems) > 0 {
return invalidTask
}
partialAgg, finalAgg := p.newPartialAggregate(storeType, false)
if partialAgg != nil {
if cop.tablePlan != nil {
cop.finishIndexPlan()
Expand Down