Skip to content

Commit

Permalink
stats: fix resource leak (#5657)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored Jan 16, 2018
1 parent 496599c commit fc09236
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions statistics/boostrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ import (
"github.com/juju/errors"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/types"
)

func (h *Handle) initStatsMeta(is infoschema.InfoSchema) (statsCache, error) {
sql := "select version, table_id, modify_count, count from mysql.stats_meta"
rs, err := h.ctx.(sqlexec.SQLExecutor).Execute(sql)
if len(rs) > 0 {
defer terror.Call(rs[0].Close)
}
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -60,6 +64,9 @@ func (h *Handle) initStatsMeta(is infoschema.InfoSchema) (statsCache, error) {
func (h *Handle) initStatsHistograms(is infoschema.InfoSchema, tables statsCache) error {
sql := "select table_id, is_index, hist_id, distinct_count, version, null_count from mysql.stats_histograms"
rs, err := h.ctx.(sqlexec.SQLExecutor).Execute(sql)
if len(rs) > 0 {
defer terror.Call(rs[0].Close)
}
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -114,6 +121,9 @@ func (h *Handle) initStatsHistograms(is infoschema.InfoSchema, tables statsCache
func (h *Handle) initStatsBuckets(tables statsCache) error {
sql := "select table_id, is_index, hist_id, bucket_id, count, repeats, lower_bound, upper_bound from mysql.stats_buckets"
rs, err := h.ctx.(sqlexec.SQLExecutor).Execute(sql)
if len(rs) > 0 {
defer terror.Call(rs[0].Close)
}
if err != nil {
return errors.Trace(err)
}
Expand Down
4 changes: 4 additions & 0 deletions statistics/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/types"
)
Expand Down Expand Up @@ -121,6 +122,9 @@ func (h *Handle) insertColStats2KV(tableID int64, colInfo *model.ColumnInfo) err
// By this step we can get the count of this table, then we can sure the count and repeats of bucket.
var rs []ast.RecordSet
rs, err = exec.Execute(fmt.Sprintf("select count from mysql.stats_meta where table_id = %d", tableID))
if len(rs) > 0 {
defer terror.Call(rs[0].Close)
}
if err != nil {
return errors.Trace(err)
}
Expand Down

0 comments on commit fc09236

Please sign in to comment.