Skip to content

Commit bc7ffdc

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 719f68e commit bc7ffdc

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

pkg/statistics/handle/handle_hist.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/pingcap/tidb/pkg/parser/mysql"
2929
"github.com/pingcap/tidb/pkg/sessionctx"
3030
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
31+
"github.com/pingcap/tidb/pkg/sessionctx/variable"
3132
"github.com/pingcap/tidb/pkg/statistics"
3233
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
3334
utilstats "github.com/pingcap/tidb/pkg/statistics/handle/util"
@@ -280,6 +281,19 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
280281
h.SPool().Put(se)
281282
}
282283
}()
284+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
285+
=======
286+
var skipTypes map[string]struct{}
287+
val, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeSkipColumnTypes)
288+
if err != nil {
289+
logutil.BgLogger().Warn("failed to get global variable", zap.Error(err))
290+
} else {
291+
skipTypes = variable.ParseAnalyzeSkipColumnTypes(val)
292+
}
293+
294+
item := task.Item.TableItemID
295+
tbl, ok := s.statsHandle.Get(item.TableID)
296+
>>>>>>> bfec7325a12 (statsitstics: avoid sync load column which is skiped type to analyze (#57144)):pkg/statistics/handle/syncload/stats_syncload.go
283297

284298
item := task.TableItemID
285299
tbl, ok := h.Get(item.TableID)
@@ -294,12 +308,44 @@ func (h *Handle) handleOneItemTask(task *NeededItemTask) (err error) {
294308
}
295309
wrapper.idx = index
296310
} else {
311+
<<<<<<< HEAD:pkg/statistics/handle/handle_hist.go
297312
col, ok := tbl.Columns[item.ID]
298313
if !ok || col.IsFullLoad() {
314+
=======
315+
col, loadNeeded, analyzed := tbl.ColumnIsLoadNeeded(item.ID, task.Item.FullLoad)
316+
if !loadNeeded {
317+
return nil
318+
}
319+
if col != nil {
320+
wrapper.colInfo = col.Info
321+
} else {
322+
// Now, we cannot init the column info in the ColAndIdxExistenceMap when to disable lite-init-stats.
323+
// so we have to get the column info from the domain.
324+
wrapper.colInfo = tblInfo.Meta().GetColumnByID(item.ID)
325+
}
326+
if skipTypes != nil {
327+
_, skip := skipTypes[types.TypeToStr(wrapper.colInfo.FieldType.GetType(), wrapper.colInfo.FieldType.GetCharset())]
328+
if skip {
329+
return nil
330+
}
331+
}
332+
333+
// If this column is not analyzed yet and we don't have it in memory.
334+
// We create a fake one for the pseudo estimation.
335+
if loadNeeded && !analyzed {
336+
wrapper.col = &statistics.Column{
337+
PhysicalID: item.TableID,
338+
Info: wrapper.colInfo,
339+
Histogram: *statistics.NewHistogram(item.ID, 0, 0, 0, &wrapper.colInfo.FieldType, 0, 0),
340+
IsHandle: isPkIsHandle && mysql.HasPriKeyFlag(wrapper.colInfo.GetFlag()),
341+
}
342+
s.updateCachedItem(tblInfo, item, wrapper.col, wrapper.idx, task.Item.FullLoad)
343+
>>>>>>> bfec7325a12 (statsitstics: avoid sync load column which is skiped type to analyze (#57144)):pkg/statistics/handle/syncload/stats_syncload.go
299344
return nil
300345
}
301346
wrapper.col = col
302347
}
348+
failpoint.Inject("handleOneItemTaskPanic", nil)
303349
t := time.Now()
304350
needUpdate := false
305351
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)