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

executor: fix firstrow/max/min(bit col) error #7206

Merged
merged 9 commits into from
Aug 1, 2018
6 changes: 6 additions & 0 deletions executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func buildFirstRow(aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc {
}

evalType, fieldType := aggFuncDesc.RetTp.EvalType(), aggFuncDesc.RetTp
if fieldType.Tp == mysql.TypeBit {
evalType = types.ETString
}
switch aggFuncDesc.Mode {
case aggregation.DedupMode:
default:
Expand Down Expand Up @@ -215,6 +218,9 @@ func buildMaxMin(aggFuncDesc *aggregation.AggFuncDesc, ordinal int, isMax bool)
}

evalType, fieldType := aggFuncDesc.RetTp.EvalType(), aggFuncDesc.RetTp
if fieldType.Tp == mysql.TypeBit {
evalType = types.ETString
}
switch aggFuncDesc.Mode {
case aggregation.DedupMode:
default:
Expand Down
11 changes: 11 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ func (s *testSuite) TestAggregation(c *C) {
result = tk.MustQuery("select t.id, count(95), sum(95), avg(95), bit_or(95), bit_and(95), bit_or(95), max(95), min(95), group_concat(95) from t left join s on t.id = s.id")
result.Check(testkit.Rows("1 1 95 95.0000 95 95 95 95 95 95"))
tk.MustExec("set @@tidb_hash_join_concurrency=5")

// test agg bit col
tk.MustExec("drop table t")
tk.MustExec("CREATE TABLE `t` (`a` bit(1) NOT NULL, PRIMARY KEY (`a`))")
tk.MustExec("insert into t value(1), (0)")
tk.MustQuery("select a from t group by 1")
// This result is compatible with MySQL, the readable result is shown in the next case.
result = tk.MustQuery("select max(a) from t group by a")
result.Check(testkit.Rows(string([]byte{0x0}), string([]byte{0x1})))
result = tk.MustQuery("select cast(a as signed) as idx, cast(max(a) as signed), cast(min(a) as signed) from t group by 1 order by idx")
result.Check(testkit.Rows("0 0 0", "1 1 1"))
}

func (s *testSuite) TestStreamAggPushDown(c *C) {
Expand Down