diff --git a/executor/aggregate.go b/executor/aggregate.go index 8f66f41def76a..7d807aeb49edb 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -1465,12 +1465,12 @@ func (e *vecGroupChecker) splitIntoGroups(chk *chunk.Chunk) (isFirstGroupSameAsP return false, err } } - e.firstGroupKey, err = codec.EncodeValue(e.ctx.GetSessionVars().StmtCtx, e.firstGroupKey, e.firstRowDatums...) + e.firstGroupKey, err = codec.EncodeKey(e.ctx.GetSessionVars().StmtCtx, e.firstGroupKey, e.firstRowDatums...) if err != nil { return false, err } - e.lastGroupKey, err = codec.EncodeValue(e.ctx.GetSessionVars().StmtCtx, e.lastGroupKey, e.lastRowDatums...) + e.lastGroupKey, err = codec.EncodeKey(e.ctx.GetSessionVars().StmtCtx, e.lastGroupKey, e.lastRowDatums...) if err != nil { return false, err } diff --git a/executor/executor_issue_test.go b/executor/executor_issue_test.go index 08e4e14031ebd..e2caddb9179dc 100644 --- a/executor/executor_issue_test.go +++ b/executor/executor_issue_test.go @@ -1314,3 +1314,21 @@ func TestIssue40158(t *testing.T) { tk.MustExec("insert into t1 values (1, null);") tk.MustQuery("select * from t1 where c1 is null and _id < 1;").Check(testkit.Rows()) } + +func TestIssue49902(t *testing.T) { + store, clean := testkit.CreateMockStore(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("set @@tidb_max_chunk_size = 32;") + tk.MustExec("drop table if exists t, s;") + tk.MustExec("CREATE TABLE `t` (`c` char(1)) COLLATE=utf8_general_ci ;") + tk.MustExec("insert into t values(\"V\"),(\"v\");") + tk.MustExec("insert into t values(\"V\"),(\"v\"),(\"v\");") + tk.MustExec("CREATE TABLE `s` (`col_61` int);") + tk.MustExec("insert into s values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1);") + tk.MustExec("insert into s values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1);") + tk.MustQuery("SELECT /*+ stream_agg()*/ count(`t`.`c`) FROM (`s`) JOIN `t` GROUP BY `t`.`c`;").Check(testkit.Rows("170")) + tk.MustQuery("SELECT count(`t`.`c`) FROM (`s`) JOIN `t` GROUP BY `t`.`c`;").Check(testkit.Rows("170")) + tk.MustExec("set @@tidb_max_chunk_size = default;") +}