Skip to content

Commit

Permalink
stats: reduce conflict for updating column size (#7124)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored Jul 24, 2018
1 parent ade23a0 commit 46e46c1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions statistics/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"math"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -344,17 +345,16 @@ func (h *Handle) dumpTableStatColSizeToKV(id int64, delta variable.TableDelta) (
err = finishTransaction(ctx, exec, err)
}()
version := h.mu.ctx.Txn().StartTS()

for key, val := range delta.ColSize {
if val == 0 {
values := make([]string, 0, len(delta.ColSize))
for histID, deltaColSize := range delta.ColSize {
if deltaColSize == 0 {
continue
}
sql := fmt.Sprintf("update mysql.stats_histograms set version = %d, tot_col_size = tot_col_size + %d where hist_id = %d and table_id = %d and is_index = 0", version, val, key, id)
_, err = exec.Execute(ctx, sql)
if err != nil {
return
}
values = append(values, fmt.Sprintf("(%d, 0, %d, 0, %d, %d)", id, histID, deltaColSize, version))
}
sql := fmt.Sprintf("insert into mysql.stats_histograms (table_id, is_index, hist_id, distinct_count, tot_col_size, version) "+
"values %s on duplicate key update tot_col_size = tot_col_size + values(tot_col_size), version = values(version)", strings.Join(values, ","))
_, err = exec.Execute(ctx, sql)
return
}

Expand Down

0 comments on commit 46e46c1

Please sign in to comment.