From 8fca74f2bc00fa8d239e202baff3ace40c3b9d53 Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Fri, 13 Mar 2020 13:09:32 +0800 Subject: [PATCH] executor: use deep copy for maxMin4JSON (#15242) (#15288) --- executor/aggfuncs/func_max_min.go | 2 +- executor/aggregate_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/executor/aggfuncs/func_max_min.go b/executor/aggfuncs/func_max_min.go index 90202403256f1..e6407f9984f0a 100644 --- a/executor/aggfuncs/func_max_min.go +++ b/executor/aggfuncs/func_max_min.go @@ -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 diff --git a/executor/aggregate_test.go b/executor/aggregate_test.go index c10e89f6fe8ad..b4d70aa8f3fc3 100644 --- a/executor/aggregate_test.go +++ b/executor/aggregate_test.go @@ -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")) + +}