Skip to content

Commit

Permalink
statistics: reduce small obj alloc for PreCalculateScalar (#52623) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Apr 17, 2024
1 parent 5ccadf8 commit c69f844
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pkg/statistics/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,26 @@ func (hg *Histogram) PreCalculateScalar() {
}
switch hg.GetLower(0).Kind() {
case types.KindMysqlDecimal, types.KindMysqlTime:
var lower, upper types.Datum
hg.Scalars = make([]scalar, l)
for i := 0; i < l; i++ {
hg.Scalars[i] = scalar{
lower: convertDatumToScalar(hg.GetLower(i), 0),
upper: convertDatumToScalar(hg.GetUpper(i), 0),
}
// It's read-only, so we don't need to allocate new datum each time.
hg.LowerToDatum(i, &lower)
hg.UpperToDatum(i, &upper)
hg.Scalars[i].lower = convertDatumToScalar(&lower, 0)
hg.Scalars[i].upper = convertDatumToScalar(&upper, 0)
}
case types.KindBytes, types.KindString:
var lower, upper types.Datum
hg.Scalars = make([]scalar, l)
for i := 0; i < l; i++ {
lower, upper := hg.GetLower(i), hg.GetUpper(i)
// It's read-only, so we don't need to allocate new datum each time.
hg.LowerToDatum(i, &lower)
hg.UpperToDatum(i, &upper)
common := commonPrefixLength(lower.GetBytes(), upper.GetBytes())
hg.Scalars[i] = scalar{
commonPfxLen: common,
lower: convertDatumToScalar(lower, common),
upper: convertDatumToScalar(upper, common),
}
hg.Scalars[i].commonPfxLen = common
hg.Scalars[i].lower = convertDatumToScalar(&lower, common)
hg.Scalars[i].upper = convertDatumToScalar(&upper, common)
}
}
}
Expand Down

0 comments on commit c69f844

Please sign in to comment.