Skip to content

Commit dd37138

Browse files
XuHuaiyushenli
authored andcommitted
*: support parallel hash agg (#6658)
1 parent 8c66635 commit dd37138

13 files changed

Lines changed: 791 additions & 106 deletions

executor/aggregate.go

Lines changed: 564 additions & 10 deletions
Large diffs are not rendered by default.

executor/aggregate_test.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,53 +39,53 @@ func (s *testSuite) TestAggregation(c *C) {
3939
tk.MustQuery("select bit_xor(c) from t where NULL").Check(testkit.Rows("0"))
4040
result := tk.MustQuery("select count(*) from t")
4141
result.Check(testkit.Rows("7"))
42-
result = tk.MustQuery("select count(*) from t group by d")
42+
result = tk.MustQuery("select count(*) from t group by d order by c")
4343
result.Check(testkit.Rows("3", "2", "2"))
4444
result = tk.MustQuery("select distinct 99 from t group by d having d > 0")
4545
result.Check(testkit.Rows("99"))
4646
result = tk.MustQuery("select count(*) from t having 1 = 0")
4747
result.Check(testkit.Rows())
48-
result = tk.MustQuery("select c,d from t group by d")
48+
result = tk.MustQuery("select c,d from t group by d order by d")
4949
result.Check(testkit.Rows("<nil> 1", "1 2", "1 3"))
5050
result = tk.MustQuery("select - c, c as d from t group by c having null not between c and avg(distinct d) - d")
5151
result.Check(testkit.Rows())
5252
result = tk.MustQuery("select - c as c from t group by c having t.c > 5")
5353
result.Check(testkit.Rows())
5454
result = tk.MustQuery("select t1.c from t t1, t t2 group by c having c > 5")
5555
result.Check(testkit.Rows())
56-
result = tk.MustQuery("select count(*) from (select d, c from t) k where d != 0 group by d")
56+
result = tk.MustQuery("select count(*) from (select d, c from t) k where d != 0 group by d order by c")
5757
result.Check(testkit.Rows("3", "2", "2"))
5858
result = tk.MustQuery("select c as a from t group by d having a < 0")
5959
result.Check(testkit.Rows())
6060
result = tk.MustQuery("select c as a from t group by d having sum(a) = 2")
6161
result.Check(testkit.Rows("<nil>"))
62-
result = tk.MustQuery("select count(distinct c) from t group by d")
62+
result = tk.MustQuery("select count(distinct c) from t group by d order by c")
6363
result.Check(testkit.Rows("1", "2", "2"))
64-
result = tk.MustQuery("select sum(c) from t group by d")
64+
result = tk.MustQuery("select sum(c) as a from t group by d order by a")
6565
result.Check(testkit.Rows("2", "4", "5"))
66-
result = tk.MustQuery("select sum(c), sum(c+1), sum(c), sum(c+1) from t group by d")
66+
result = tk.MustQuery("select sum(c) as a, sum(c+1), sum(c), sum(c+1) from t group by d order by a")
6767
result.Check(testkit.Rows("2 4 2 4", "4 6 4 6", "5 7 5 7"))
6868
result = tk.MustQuery("select count(distinct c,d) from t")
6969
result.Check(testkit.Rows("5"))
7070
_, err := tk.Exec("select count(c,d) from t")
7171
c.Assert(err, NotNil)
72-
result = tk.MustQuery("select d*2 as ee, sum(c) from t group by ee")
72+
result = tk.MustQuery("select d*2 as ee, sum(c) from t group by ee order by ee")
7373
result.Check(testkit.Rows("2 2", "4 4", "6 5"))
74-
result = tk.MustQuery("select sum(distinct c) from t group by d")
74+
result = tk.MustQuery("select sum(distinct c) as a from t group by d order by a")
7575
result.Check(testkit.Rows("1", "4", "5"))
76-
result = tk.MustQuery("select min(c) from t group by d")
76+
result = tk.MustQuery("select min(c) as a from t group by d order by a")
7777
result.Check(testkit.Rows("1", "1", "1"))
78-
result = tk.MustQuery("select max(c) from t group by d")
78+
result = tk.MustQuery("select max(c) as a from t group by d order by a")
7979
result.Check(testkit.Rows("1", "3", "4"))
80-
result = tk.MustQuery("select avg(c) from t group by d")
80+
result = tk.MustQuery("select avg(c) as a from t group by d order by a")
8181
result.Check(testkit.Rows("1.0000", "2.0000", "2.5000"))
82-
result = tk.MustQuery("select d, d + 1 from t group by d")
82+
result = tk.MustQuery("select d, d + 1 from t group by d order by d")
8383
result.Check(testkit.Rows("1 2", "2 3", "3 4"))
8484
result = tk.MustQuery("select count(*) from t")
8585
result.Check(testkit.Rows("7"))
8686
result = tk.MustQuery("select count(distinct d) from t")
8787
result.Check(testkit.Rows("3"))
88-
result = tk.MustQuery("select count(*) from t group by d having sum(c) > 3")
88+
result = tk.MustQuery("select count(*) as a from t group by d having sum(c) > 3 order by a")
8989
result.Check(testkit.Rows("2", "2"))
9090
result = tk.MustQuery("select max(c) from t group by d having sum(c) > 3 order by avg(c) desc")
9191
result.Check(testkit.Rows("4", "3"))
@@ -107,7 +107,7 @@ func (s *testSuite) TestAggregation(c *C) {
107107
result.Check(testkit.Rows("343"))
108108
result = tk.MustQuery("select count(*) from t a , t b where a.c = b.d")
109109
result.Check(testkit.Rows("14"))
110-
result = tk.MustQuery("select count(a.d), sum(b.c) from t a , t b where a.c = b.d")
110+
result = tk.MustQuery("select count(a.d), sum(b.c) from t a , t b where a.c = b.d order by a.d")
111111
result.Check(testkit.Rows("14 13"))
112112
result = tk.MustQuery("select count(*) from t a , t b, t c where a.c = b.d and b.d = c.d")
113113
result.Check(testkit.Rows("40"))
@@ -146,29 +146,29 @@ func (s *testSuite) TestAggregation(c *C) {
146146
result.Check(testkit.Rows("1 0 1", "0 1 1", "-1 2 1"))
147147
result = tk.MustQuery("select d, 1-d as d, c as d from t order by d+1")
148148
result.Check(testkit.Rows("-1 2 1", "0 1 1", "1 0 1"))
149-
result = tk.MustQuery("select d, 1-d as d, c as d from t group by d")
150-
result.Check(testkit.Rows("-1 2 1", "0 1 1", "1 0 1"))
151-
result = tk.MustQuery("select d as d1, t.d as d1, 1-d as d1, c as d1 from t having d1 < 10")
149+
result = tk.MustQuery("select d, 1-d as d, c as d from t group by d order by d")
150+
result.Check(testkit.Rows("1 0 1", "0 1 1", "-1 2 1"))
151+
result = tk.MustQuery("select d as d1, t.d as d1, 1-d as d1, c as d1 from t having d1 < 10 order by d")
152152
result.Check(testkit.Rows("-1 -1 2 1", "0 0 1 1", "1 1 0 1"))
153-
result = tk.MustQuery("select d*d as d1, c as d1 from t group by d1")
154-
result.Check(testkit.Rows("1 1", "0 1"))
153+
result = tk.MustQuery("select d*d as d1, c as d1 from t group by d1 order by d1")
154+
result.Check(testkit.Rows("0 1", "1 1"))
155155
result = tk.MustQuery("select d*d as d1, c as d1 from t group by 2")
156156
result.Check(testkit.Rows("1 1"))
157-
result = tk.MustQuery("select * from t group by 2")
157+
result = tk.MustQuery("select * from t group by 2 order by d")
158158
result.Check(testkit.Rows("1 -1", "1 0", "1 1"))
159-
result = tk.MustQuery("select * , sum(d) from t group by 1")
159+
result = tk.MustQuery("select * , sum(d) from t group by 1 order by d")
160160
result.Check(testkit.Rows("1 -1 0"))
161-
result = tk.MustQuery("select sum(d), t.* from t group by 2")
161+
result = tk.MustQuery("select sum(d), t.* from t group by 2 order by d")
162162
result.Check(testkit.Rows("0 1 -1"))
163-
result = tk.MustQuery("select d as d, c as d from t group by d + 1")
163+
result = tk.MustQuery("select d as d, c as d from t group by d + 1 order by t.d")
164164
result.Check(testkit.Rows("-1 1", "0 1", "1 1"))
165-
result = tk.MustQuery("select c as d, c as d from t group by d")
165+
result = tk.MustQuery("select c as d, c as d from t group by d order by d")
166166
result.Check(testkit.Rows("1 1", "1 1", "1 1"))
167167
_, err = tk.Exec("select d as d, c as d from t group by d")
168168
c.Assert(err, NotNil)
169169
_, err = tk.Exec("select t.d, c as d from t group by d")
170170
c.Assert(err, NotNil)
171-
result = tk.MustQuery("select *, c+1 as d from t group by 3")
171+
result = tk.MustQuery("select *, c+1 as d from t group by 3 order by d")
172172
result.Check(testkit.Rows("1 -1 2"))
173173
tk.MustExec("drop table if exists t1")
174174
tk.MustExec("create table t1(a float, b int default 3)")
@@ -188,41 +188,41 @@ func (s *testSuite) TestAggregation(c *C) {
188188
result = tk.MustQuery("select sum(b) from (select * from t1) t")
189189
result.Check(testkit.Rows("<nil>"))
190190
tk.MustExec("insert into t1 (a, b) values (1, 1),(2, 2),(3, 3),(1, 4),(3, 5)")
191-
result = tk.MustQuery("select avg(b) from (select * from t1) t group by a")
191+
result = tk.MustQuery("select avg(b) from (select * from t1) t group by a order by a")
192192
result.Check(testkit.Rows("2.5000", "2.0000", "4.0000"))
193-
result = tk.MustQuery("select sum(b) from (select * from t1) t group by a")
193+
result = tk.MustQuery("select sum(b) from (select * from t1) t group by a order by a")
194194
result.Check(testkit.Rows("5", "2", "8"))
195-
result = tk.MustQuery("select count(b) from (select * from t1) t group by a")
195+
result = tk.MustQuery("select count(b) from (select * from t1) t group by a order by a")
196196
result.Check(testkit.Rows("2", "1", "2"))
197-
result = tk.MustQuery("select max(b) from (select * from t1) t group by a")
197+
result = tk.MustQuery("select max(b) from (select * from t1) t group by a order by a")
198198
result.Check(testkit.Rows("4", "2", "5"))
199-
result = tk.MustQuery("select min(b) from (select * from t1) t group by a")
199+
result = tk.MustQuery("select min(b) from (select * from t1) t group by a order by a")
200200
result.Check(testkit.Rows("1", "2", "3"))
201201
tk.MustExec("drop table if exists t1")
202202
tk.MustExec("create table t1(a int, b int, index(a,b))")
203203
tk.MustExec("insert into t1 (a, b) values (1, 1),(2, 2),(3, 3),(1, 4), (1,1),(3, 5), (2,2), (3,5), (3,3)")
204-
result = tk.MustQuery("select avg(distinct b) from (select * from t1) t group by a")
204+
result = tk.MustQuery("select avg(distinct b) from (select * from t1) t group by a order by a")
205205
result.Check(testkit.Rows("2.5000", "2.0000", "4.0000"))
206-
result = tk.MustQuery("select sum(distinct b) from (select * from t1) t group by a")
206+
result = tk.MustQuery("select sum(distinct b) from (select * from t1) t group by a order by a")
207207
result.Check(testkit.Rows("5", "2", "8"))
208-
result = tk.MustQuery("select count(distinct b) from (select * from t1) t group by a")
208+
result = tk.MustQuery("select count(distinct b) from (select * from t1) t group by a order by a")
209209
result.Check(testkit.Rows("2", "1", "2"))
210-
result = tk.MustQuery("select max(distinct b) from (select * from t1) t group by a")
210+
result = tk.MustQuery("select max(distinct b) from (select * from t1) t group by a order by a")
211211
result.Check(testkit.Rows("4", "2", "5"))
212-
result = tk.MustQuery("select min(distinct b) from (select * from t1) t group by a")
212+
result = tk.MustQuery("select min(distinct b) from (select * from t1) t group by a order by a")
213213
result.Check(testkit.Rows("1", "2", "3"))
214214
tk.MustExec("drop table if exists t1")
215215
tk.MustExec("create table t1(a int, b int, index(b, a))")
216216
tk.MustExec("insert into t1 (a, b) values (1, 1),(2, 2),(3, 3),(1, 4), (1,1),(3, 5), (2,2), (3,5), (3,3)")
217-
result = tk.MustQuery("select avg(distinct b) from (select * from t1) t group by a")
217+
result = tk.MustQuery("select avg(distinct b) from (select * from t1) t group by a order by a")
218218
result.Check(testkit.Rows("2.5000", "2.0000", "4.0000"))
219-
result = tk.MustQuery("select sum(distinct b) from (select * from t1) t group by a")
219+
result = tk.MustQuery("select sum(distinct b) from (select * from t1) t group by a order by a")
220220
result.Check(testkit.Rows("5", "2", "8"))
221-
result = tk.MustQuery("select count(distinct b) from (select * from t1) t group by a")
221+
result = tk.MustQuery("select count(distinct b) from (select * from t1) t group by a order by a")
222222
result.Check(testkit.Rows("2", "1", "2"))
223-
result = tk.MustQuery("select max(distinct b) from (select * from t1) t group by a")
223+
result = tk.MustQuery("select max(distinct b) from (select * from t1) t group by a order by a")
224224
result.Check(testkit.Rows("4", "2", "5"))
225-
result = tk.MustQuery("select min(distinct b) from (select * from t1) t group by a")
225+
result = tk.MustQuery("select min(distinct b) from (select * from t1) t group by a order by a")
226226
result.Check(testkit.Rows("1", "2", "3"))
227227
tk.MustExec("drop table if exists t")
228228
tk.MustExec("create table t (id int primary key, ds date)")
@@ -274,12 +274,12 @@ func (s *testSuite) TestAggregation(c *C) {
274274
tk.MustExec("drop table if exists t")
275275
tk.MustExec("create table t(a int(11), b decimal(15,2))")
276276
tk.MustExec("insert into t values(1,771.64),(2,378.49),(3,920.92),(4,113.97)")
277-
tk.MustQuery("select a, max(b) from t group by a limit 2").Check(testkit.Rows("1 771.64", "2 378.49"))
277+
tk.MustQuery("select a, max(b) from t group by a order by a limit 2").Check(testkit.Rows("1 771.64", "2 378.49"))
278278

279279
tk.MustExec("drop table if exists t")
280280
tk.MustExec("create table t(a int(11), b char(15))")
281281
tk.MustExec("insert into t values(1,771.64),(2,378.49),(3,920.92),(4,113.97)")
282-
tk.MustQuery("select a, max(b) from t group by a limit 2").Check(testkit.Rows("1 771.64", "2 378.49"))
282+
tk.MustQuery("select a, max(b) from t group by a order by a limit 2").Check(testkit.Rows("1 771.64", "2 378.49"))
283283

284284
// for issue #6014
285285
tk.MustExec("use test")
@@ -347,19 +347,19 @@ func (s *testSuite) TestGroupConcatAggr(c *C) {
347347
tk.MustExec("insert into test values(2, 20);")
348348
tk.MustExec("insert into test values(3, 200);")
349349
tk.MustExec("insert into test values(3, 500);")
350-
result := tk.MustQuery("select id, group_concat(name) from test group by id")
350+
result := tk.MustQuery("select id, group_concat(name) from test group by id order by id")
351351
result.Check(testkit.Rows("1 10,20,30", "2 20", "3 200,500"))
352352

353-
result = tk.MustQuery("select id, group_concat(name SEPARATOR ';') from test group by id")
353+
result = tk.MustQuery("select id, group_concat(name SEPARATOR ';') from test group by id order by id")
354354
result.Check(testkit.Rows("1 10;20;30", "2 20", "3 200;500"))
355355

356-
result = tk.MustQuery("select id, group_concat(name SEPARATOR ',') from test group by id")
356+
result = tk.MustQuery("select id, group_concat(name SEPARATOR ',') from test group by id order by id")
357357
result.Check(testkit.Rows("1 10,20,30", "2 20", "3 200,500"))
358358

359-
result = tk.MustQuery(`select id, group_concat(name SEPARATOR '%') from test group by id`)
359+
result = tk.MustQuery(`select id, group_concat(name SEPARATOR '%') from test group by id order by id`)
360360
result.Check(testkit.Rows("1 10%20%30", "2 20", `3 200%500`))
361361

362-
result = tk.MustQuery("select id, group_concat(name SEPARATOR '') from test group by id")
362+
result = tk.MustQuery("select id, group_concat(name SEPARATOR '') from test group by id order by id")
363363
result.Check(testkit.Rows("1 102030", "2 20", "3 200500"))
364364
}
365365

@@ -384,7 +384,7 @@ func (s *testSuite) TestAggPushDown(c *C) {
384384
tk.MustExec("insert into t values(1, 1, 1), (2, 1, 1)")
385385
tk.MustExec("insert into tt values(1, 2, 1)")
386386
tk.MustQuery("select max(a.b), max(b.b) from t a join tt b on a.a = b.a group by a.c").Check(testkit.Rows("1 2"))
387-
tk.MustQuery("select a, count(b) from (select * from t union all select * from tt) k group by a").Check(testkit.Rows("1 2", "2 1"))
387+
tk.MustQuery("select a, count(b) from (select * from t union all select * from tt) k group by a order by a").Check(testkit.Rows("1 2", "2 1"))
388388
}
389389

390390
func (s *testSuite) TestOnlyFullGroupBy(c *C) {
@@ -518,8 +518,8 @@ func (s *testSuite) TestHaving(c *C) {
518518
tk.MustQuery("select c1 as a from t group by c3 having sum(a) + a = 2;").Check(testkit.Rows("1"))
519519
tk.MustQuery("select a.c1 as c, a.c1 as d from t as a, t as b having c1 = 1 limit 1;").Check(testkit.Rows("1 1"))
520520

521-
tk.MustQuery("select sum(c1) from t group by c1 having sum(c1)").Check(testkit.Rows("1", "2", "3"))
522-
tk.MustQuery("select sum(c1) - 1 from t group by c1 having sum(c1) - 1").Check(testkit.Rows("1", "2"))
521+
tk.MustQuery("select sum(c1) as s from t group by c1 having sum(c1) order by s").Check(testkit.Rows("1", "2", "3"))
522+
tk.MustQuery("select sum(c1) - 1 as s from t group by c1 having sum(c1) - 1 order by s").Check(testkit.Rows("1", "2"))
523523
tk.MustQuery("select 1 from t group by c1 having sum(abs(c2 + c3)) = c1").Check(testkit.Rows("1"))
524524
}
525525

@@ -566,7 +566,7 @@ func (s *testSuite) TestBuildProjBelowAgg(c *C) {
566566
tk.MustExec("drop table if exists t;")
567567
tk.MustExec("create table t (i int);")
568568
tk.MustExec("insert into t values (1), (1), (1),(2),(3),(2),(3),(2),(3);")
569-
rs := tk.MustQuery("select i+1, count(i+2), sum(i+3), group_concat(i+4), bit_or(i+5) from t group by i, hex(i+6)")
569+
rs := tk.MustQuery("select i+1 as a, count(i+2), sum(i+3), group_concat(i+4), bit_or(i+5) from t group by i, hex(i+6) order by a")
570570
rs.Check(testkit.Rows(
571571
"2 3 12 5,5,5 6",
572572
"3 3 15 6,6,6 7",

executor/builder.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/pingcap/tidb/table"
4343
"github.com/pingcap/tidb/types"
4444
"github.com/pingcap/tidb/util/admin"
45+
"github.com/pingcap/tidb/util/chunk"
4546
"github.com/pingcap/tidb/util/ranger"
4647
"github.com/pingcap/tipb/go-tipb"
4748
"golang.org/x/net/context"
@@ -900,9 +901,58 @@ func (b *executorBuilder) buildHashAgg(v *plan.PhysicalHashAgg) Executor {
900901
AggFuncs: make([]aggregation.Aggregation, 0, len(v.AggFuncs)),
901902
GroupByItems: v.GroupByItems,
902903
}
904+
// We take `create table t(a int, b int);` as example.
905+
//
906+
// 1. If all the aggregation functions are FIRST_ROW, we do not need to set the defaultVal for them:
907+
// e.g.
908+
// mysql> select distinct a, b from t;
909+
// 0 rows in set (0.00 sec)
910+
//
911+
// 2. If there exists group by items, we do not need to set the defaultVal for them either:
912+
// e.g.
913+
// mysql> select avg(a) from t group by b;
914+
// Empty set (0.00 sec)
915+
//
916+
// mysql> select avg(a) from t group by a;
917+
// +--------+
918+
// | avg(a) |
919+
// +--------+
920+
// | NULL |
921+
// +--------+
922+
// 1 row in set (0.00 sec)
923+
if len(v.GroupByItems) != 0 || aggregation.IsAllFirstRow(v.AggFuncs) {
924+
e.defaultVal = nil
925+
} else {
926+
e.defaultVal = chunk.NewChunkWithCapacity(e.retTypes(), 1)
927+
}
903928
for _, aggDesc := range v.AggFuncs {
929+
if aggDesc.HasDistinct {
930+
e.isUnparallelExec = true
931+
}
932+
}
933+
// When we set both tidb_hashagg_final_concurrency and tidb_hashagg_partial_concurrency to 1,
934+
// we do not need to parallelly execute hash agg,
935+
// and this action can be a workaround when meeting some unexpected situation using parallelExec.
936+
if finalCon, partialCon := sessionVars.HashAggFinalConcurrency, sessionVars.HashAggPartialConcurrency; finalCon <= 0 || partialCon <= 0 || finalCon == 1 && partialCon == 1 {
937+
e.isUnparallelExec = true
938+
}
939+
for i, aggDesc := range v.AggFuncs {
940+
if !e.isUnparallelExec {
941+
if aggDesc.Mode == aggregation.CompleteMode {
942+
aggDesc.Mode = aggregation.Partial1Mode
943+
} else {
944+
aggDesc.Mode = aggregation.Partial2Mode
945+
}
946+
}
904947
e.AggFuncs = append(e.AggFuncs, aggDesc.GetAggFunc())
948+
if e.defaultVal != nil {
949+
value, existsDefaultValue := aggDesc.CalculateDefaultValue(e.ctx, e.children[0].Schema())
950+
if existsDefaultValue {
951+
e.defaultVal.AppendDatum(i, &value)
952+
}
953+
}
905954
}
955+
906956
metrics.ExecutorCounter.WithLabelValues("HashAggExec").Inc()
907957
return e
908958
}

executor/executor_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -822,12 +822,8 @@ func (s *testSuite) TestUnion(c *C) {
822822
testSQL = `insert union_test values (1),(2)`
823823
tk.MustExec(testSQL)
824824

825-
testSQL = `select id from union_test union select id from union_test;`
826-
r := tk.MustQuery(testSQL)
827-
r.Check(testkit.Rows("1", "2"))
828-
829825
testSQL = `select * from (select id from union_test union select id from union_test) t order by id;`
830-
r = tk.MustQuery(testSQL)
826+
r := tk.MustQuery(testSQL)
831827
r.Check(testkit.Rows("1", "2"))
832828

833829
r = tk.MustQuery("select 1 union all select 1")
@@ -895,7 +891,7 @@ func (s *testSuite) TestUnion(c *C) {
895891
tk.MustExec("insert into t (c1, c2) values (1, 1)")
896892
tk.MustExec("insert into t (c1, c2) values (1, 2)")
897893
tk.MustExec("insert into t (c1, c2) values (2, 3)")
898-
r = tk.MustQuery("select * from t where t.c1 = 1 union select * from t where t.id = 1")
894+
r = tk.MustQuery("select * from (select * from t where t.c1 = 1 union select * from t where t.id = 1) s order by s.id")
899895
r.Check(testkit.Rows("1 1 1", "2 1 2"))
900896

901897
tk.MustExec("drop table if exists t")
@@ -1865,9 +1861,9 @@ func (s *testSuite) TestSimpleDAG(c *C) {
18651861
tk.MustQuery("select a from t where b > 1 and a < 3").Check(testkit.Rows())
18661862
tk.MustQuery("select count(*) from t where b > 1 and a < 3").Check(testkit.Rows("0"))
18671863
tk.MustQuery("select count(*) from t").Check(testkit.Rows("4"))
1868-
tk.MustQuery("select count(*), c from t group by c").Check(testkit.Rows("2 1", "1 2", "1 3"))
1869-
tk.MustQuery("select sum(c) from t group by b").Check(testkit.Rows("4", "3"))
1870-
tk.MustQuery("select avg(a) from t group by b").Check(testkit.Rows("2.0000", "4.0000"))
1864+
tk.MustQuery("select count(*), c from t group by c order by c").Check(testkit.Rows("2 1", "1 2", "1 3"))
1865+
tk.MustQuery("select sum(c) as s from t group by b order by s").Check(testkit.Rows("3", "4"))
1866+
tk.MustQuery("select avg(a) as s from t group by b order by s").Check(testkit.Rows("2.0000", "4.0000"))
18711867
tk.MustQuery("select sum(distinct c) from t group by b").Check(testkit.Rows("3", "3"))
18721868

18731869
tk.MustExec("create index i on t(c,b)")

0 commit comments

Comments
 (0)