Skip to content

Commit

Permalink
statistics: move TableStatsFromStorage out of handle (pingcap#40822)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyifangreeneyes authored and ghazalfamilyusa committed Feb 6, 2023
1 parent 7683358 commit 1ebee95
Show file tree
Hide file tree
Showing 6 changed files with 435 additions and 228 deletions.
7 changes: 4 additions & 3 deletions statistics/handle/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mathutil"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (h *Handle) gcTableStats(is infoschema.InfoSchema, physicalID int64) error
}
}
// Mark records in mysql.stats_extended as `deleted`.
rows, _, err = h.execRestrictedSQL(ctx, "select name, column_ids from mysql.stats_extended where table_id = %? and status in (%?, %?)", physicalID, StatsStatusAnalyzed, StatsStatusInited)
rows, _, err = h.execRestrictedSQL(ctx, "select name, column_ids from mysql.stats_extended where table_id = %? and status in (%?, %?)", physicalID, statistics.ExtendedStatsAnalyzed, statistics.ExtendedStatsInited)
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -292,7 +293,7 @@ func (h *Handle) DeleteTableStatsFromKV(statsIDs []int64) (err error) {
if _, err = exec.ExecuteInternal(ctx, "delete from mysql.stats_feedback where table_id = %?", statsID); err != nil {
return err
}
if _, err = exec.ExecuteInternal(ctx, "update mysql.stats_extended set version = %?, status = %? where table_id = %? and status in (%?, %?)", startTS, StatsStatusDeleted, statsID, StatsStatusAnalyzed, StatsStatusInited); err != nil {
if _, err = exec.ExecuteInternal(ctx, "update mysql.stats_extended set version = %?, status = %? where table_id = %? and status in (%?, %?)", startTS, statistics.ExtendedStatsDeleted, statsID, statistics.ExtendedStatsAnalyzed, statistics.ExtendedStatsInited); err != nil {
return err
}
if _, err = exec.ExecuteInternal(ctx, "delete from mysql.stats_fm_sketch where table_id = %?", statsID); err != nil {
Expand Down Expand Up @@ -321,6 +322,6 @@ func (h *Handle) removeDeletedExtendedStats(version uint64) (err error) {
err = finishTransaction(ctx, exec, err)
}()
const sql = "delete from mysql.stats_extended where status = %? and version < %?"
_, err = exec.ExecuteInternal(ctx, sql, StatsStatusDeleted, version)
_, err = exec.ExecuteInternal(ctx, sql, statistics.ExtendedStatsDeleted, version)
return
}
Loading

0 comments on commit 1ebee95

Please sign in to comment.