Skip to content

Commit

Permalink
executor: use deep copy for maxMin4JSON (#15242) (#15288)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Mar 13, 2020
1 parent 78d1a93 commit 8fca74f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/aggfuncs/func_max_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func (e *maxMin4JSON) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup [
}
cmp := json.CompareBinary(input, p.val)
if e.isMax && cmp > 0 || !e.isMax && cmp < 0 {
p.val = input
p.val = input.Copy()
}
}
return nil
Expand Down
14 changes: 14 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,17 @@ func (s *testSuite) TestIssue10608(c *C) {
tk.MustExec("INSERT INTO s VALUES (100292, 508931),(120002, 508932);")
tk.MustQuery("select (select group_concat(concat(123,'-')) from t where t.id = b group by t.id) from s;").Check(testkit.Rows("123-", "123-"))
}

func (s *testSuite) TestPR15242ShallowCopy(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(a json);`)
tk.MustExec(`insert into t values ('{"id": 1,"score":23}');`)
tk.MustExec(`insert into t values ('{"id": 2,"score":23}');`)
tk.MustExec(`insert into t values ('{"id": 1,"score":233}');`)
tk.MustExec(`insert into t values ('{"id": 2,"score":233}');`)
tk.MustExec(`insert into t values ('{"id": 3,"score":233}');`)
tk.Se.GetSessionVars().MaxChunkSize = 2
tk.MustQuery(`select max(JSON_EXTRACT(a, '$.score')) as max_score,JSON_EXTRACT(a,'$.id') as id from t group by id order by id;`).Check(testkit.Rows("233 1", "233 2", "233 3"))

}

0 comments on commit 8fca74f

Please sign in to comment.