Skip to content

Commit e5c8195

Browse files
hawkingreiti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#57144
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 7723772 commit e5c8195

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

pkg/statistics/handle/handle_hist.go

Lines changed: 40 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"
@@ -281,6 +282,19 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
281282
h.SPool().Put(se)
282283
}
283284
}()
285+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
286+
=======
287+
var skipTypes map[string]struct{}
288+
val, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeSkipColumnTypes)
289+
if err != nil {
290+
logutil.BgLogger().Warn("failed to get global variable", zap.Error(err))
291+
} else {
292+
skipTypes = variable.ParseAnalyzeSkipColumnTypes(val)
293+
}
294+
295+
item := task.Item.TableItemID
296+
tbl, ok := s.statsHandle.Get(item.TableID)
297+
>>>>>>> bfec7325a12 (statsitstics: avoid sync load column which is skiped type to analyze (#57144)):pkg/statistics/handle/syncload/stats_syncload.go
284298

285299
item := task.TableItemID
286300
tbl, ok := h.Get(item.TableID)
@@ -299,9 +313,35 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
299313
if !ok || col.IsFullLoad() {
300314
wrapper.col = nil
301315
} else {
316+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
302317
wrapper.col = col
318+
=======
319+
// Now, we cannot init the column info in the ColAndIdxExistenceMap when to disable lite-init-stats.
320+
// so we have to get the column info from the domain.
321+
wrapper.colInfo = tblInfo.Meta().GetColumnByID(item.ID)
322+
}
323+
if skipTypes != nil {
324+
_, skip := skipTypes[types.TypeToStr(wrapper.colInfo.FieldType.GetType(), wrapper.colInfo.FieldType.GetCharset())]
325+
if skip {
326+
return nil
327+
}
328+
}
329+
330+
// If this column is not analyzed yet and we don't have it in memory.
331+
// We create a fake one for the pseudo estimation.
332+
if loadNeeded && !analyzed {
333+
wrapper.col = &statistics.Column{
334+
PhysicalID: item.TableID,
335+
Info: wrapper.colInfo,
336+
Histogram: *statistics.NewHistogram(item.ID, 0, 0, 0, &wrapper.colInfo.FieldType, 0, 0),
337+
IsHandle: isPkIsHandle && mysql.HasPriKeyFlag(wrapper.colInfo.GetFlag()),
338+
}
339+
s.updateCachedItem(tblInfo, item, wrapper.col, wrapper.idx, task.Item.FullLoad)
340+
return nil
341+
>>>>>>> bfec7325a12 (statsitstics: avoid sync load column which is skiped type to analyze (#57144)):pkg/statistics/handle/syncload/stats_syncload.go
303342
}
304343
}
344+
failpoint.Inject("handleOneItemTaskPanic", nil)
305345
t := time.Now()
306346
needUpdate := false
307347
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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "syncload",
5+
srcs = ["stats_syncload.go"],
6+
importpath = "github.com/pingcap/tidb/pkg/statistics/handle/syncload",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/config",
10+
"//pkg/infoschema",
11+
"//pkg/kv",
12+
"//pkg/meta/model",
13+
"//pkg/metrics",
14+
"//pkg/parser/mysql",
15+
"//pkg/sessionctx",
16+
"//pkg/sessionctx/stmtctx",
17+
"//pkg/sessionctx/variable",
18+
"//pkg/statistics",
19+
"//pkg/statistics/handle/storage",
20+
"//pkg/statistics/handle/types",
21+
"//pkg/table",
22+
"//pkg/types",
23+
"//pkg/util",
24+
"//pkg/util/intest",
25+
"//pkg/util/logutil",
26+
"@com_github_pingcap_errors//:errors",
27+
"@com_github_pingcap_failpoint//:failpoint",
28+
"@org_golang_x_sync//singleflight",
29+
"@org_uber_go_zap//:zap",
30+
],
31+
)
32+
33+
go_test(
34+
name = "syncload_test",
35+
timeout = "short",
36+
srcs = ["stats_syncload_test.go"],
37+
flaky = True,
38+
race = "on",
39+
shard_count = 6,
40+
deps = [
41+
":syncload",
42+
"//pkg/config",
43+
"//pkg/meta/model",
44+
"//pkg/parser/model",
45+
"//pkg/sessionctx",
46+
"//pkg/sessionctx/stmtctx",
47+
"//pkg/statistics/handle/types",
48+
"//pkg/testkit",
49+
"//pkg/testkit/analyzehelper",
50+
"//pkg/util/mathutil",
51+
"@com_github_pingcap_failpoint//:failpoint",
52+
"@com_github_stretchr_testify//require",
53+
],
54+
)

0 commit comments

Comments
 (0)