Skip to content

Commit

Permalink
executor: use deep copy for maxMin4JSON (#15242)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhedu authored Mar 11, 2020
1 parent fab1c60 commit 34ff2b9
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 @@ -635,7 +635,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 @@ -830,3 +830,17 @@ func (s *testSuiteAgg) TestIssue12759HashAggCalledByApply(c *C) {
tk.MustQuery(tt).Check(testkit.Rows(output[i]...))
}
}

func (s *testSuiteAgg) 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 34ff2b9

Please sign in to comment.