Skip to content

Commit

Permalink
statsitstics: avoid sync load column which is skiped type to analyze (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 11, 2024
1 parent ee67770 commit 42e82c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/statistics/handle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ go_test(
embed = [":handle"],
flaky = True,
race = "on",
shard_count = 10,
shard_count = 11,
deps = [
"//pkg/config",
"//pkg/parser/model",
Expand Down
15 changes: 15 additions & 0 deletions pkg/statistics/handle/handle_hist.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/statistics"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
utilstats "github.com/pingcap/tidb/pkg/statistics/handle/util"
Expand Down Expand Up @@ -285,6 +286,13 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
h.SPool().Put(se)
}
}()
var skipTypes map[string]struct{}
val, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeSkipColumnTypes)
if err != nil {
logutil.BgLogger().Warn("failed to get global variable", zap.Error(err))
} else {
skipTypes = variable.ParseAnalyzeSkipColumnTypes(val)
}

item := task.TableItemID
tbl, ok := h.Get(item.TableID)
Expand All @@ -305,7 +313,14 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
} else {
wrapper.col = col
}
if skipTypes != nil && wrapper.col != nil && wrapper.col.Info != nil {
_, skip := skipTypes[types.TypeToStr(wrapper.col.Info.FieldType.GetType(), wrapper.col.Info.FieldType.GetCharset())]
if skip {
return nil
}
}
}
failpoint.Inject("handleOneItemTaskPanic", nil)
t := time.Now()
needUpdate := false
wrapper, err = h.readStatsForOneItem(sctx, item, wrapper)
Expand Down
16 changes: 16 additions & 0 deletions pkg/statistics/handle/handle_hist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ func TestSyncLoadSkipUnAnalyzedItems(t *testing.T) {
failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/assertSyncLoadItems")
}

func TestSyncLoadSkipAnalyzSkipColumnItems(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(`id` bigint(20) NOT NULL AUTO_INCREMENT,content text,PRIMARY KEY (`id`))")
h := dom.StatsHandle()
h.SetLease(1)

tk.MustExec("analyze table t")
tk.MustExec("set @@session.tidb_analyze_skip_column_types = 'json, text, blob'") // text is not default.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/statistics/handle/syncload/handleOneItemTaskPanic", `panic`))
tk.MustQuery("trace plan select * from t where content ='ab'")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/syncload/handleOneItemTaskPanic"))
}

func TestConcurrentLoadHist(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

Expand Down

0 comments on commit 42e82c4

Please sign in to comment.