Skip to content

Commit 42e82c4

Browse files
authored
statsitstics: avoid sync load column which is skiped type to analyze (#57144) (#57968)
close #57138
1 parent ee67770 commit 42e82c4

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

pkg/statistics/handle/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ go_test(
5959
embed = [":handle"],
6060
flaky = True,
6161
race = "on",
62-
shard_count = 10,
62+
shard_count = 11,
6363
deps = [
6464
"//pkg/config",
6565
"//pkg/parser/model",

pkg/statistics/handle/handle_hist.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/pingcap/tidb/pkg/parser/mysql"
3030
"github.com/pingcap/tidb/pkg/sessionctx"
3131
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
32+
"github.com/pingcap/tidb/pkg/sessionctx/variable"
3233
"github.com/pingcap/tidb/pkg/statistics"
3334
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
3435
utilstats "github.com/pingcap/tidb/pkg/statistics/handle/util"
@@ -285,6 +286,13 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
285286
h.SPool().Put(se)
286287
}
287288
}()
289+
var skipTypes map[string]struct{}
290+
val, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeSkipColumnTypes)
291+
if err != nil {
292+
logutil.BgLogger().Warn("failed to get global variable", zap.Error(err))
293+
} else {
294+
skipTypes = variable.ParseAnalyzeSkipColumnTypes(val)
295+
}
288296

289297
item := task.TableItemID
290298
tbl, ok := h.Get(item.TableID)
@@ -305,7 +313,14 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
305313
} else {
306314
wrapper.col = col
307315
}
316+
if skipTypes != nil && wrapper.col != nil && wrapper.col.Info != nil {
317+
_, skip := skipTypes[types.TypeToStr(wrapper.col.Info.FieldType.GetType(), wrapper.col.Info.FieldType.GetCharset())]
318+
if skip {
319+
return nil
320+
}
321+
}
308322
}
323+
failpoint.Inject("handleOneItemTaskPanic", nil)
309324
t := time.Now()
310325
needUpdate := false
311326
wrapper, err = h.readStatsForOneItem(sctx, item, wrapper)

pkg/statistics/handle/handle_hist_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ func TestSyncLoadSkipUnAnalyzedItems(t *testing.T) {
5151
failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/assertSyncLoadItems")
5252
}
5353

54+
func TestSyncLoadSkipAnalyzSkipColumnItems(t *testing.T) {
55+
store, dom := testkit.CreateMockStoreAndDomain(t)
56+
tk := testkit.NewTestKit(t, store)
57+
tk.MustExec("use test")
58+
tk.MustExec("drop table if exists t")
59+
tk.MustExec("create table t(`id` bigint(20) NOT NULL AUTO_INCREMENT,content text,PRIMARY KEY (`id`))")
60+
h := dom.StatsHandle()
61+
h.SetLease(1)
62+
63+
tk.MustExec("analyze table t")
64+
tk.MustExec("set @@session.tidb_analyze_skip_column_types = 'json, text, blob'") // text is not default.
65+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/statistics/handle/syncload/handleOneItemTaskPanic", `panic`))
66+
tk.MustQuery("trace plan select * from t where content ='ab'")
67+
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/syncload/handleOneItemTaskPanic"))
68+
}
69+
5470
func TestConcurrentLoadHist(t *testing.T) {
5571
store, dom := testkit.CreateMockStoreAndDomain(t)
5672

0 commit comments

Comments
 (0)