Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: fix resource leak #5657

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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