Skip to content

Commit bc9fb68

Browse files
committed
statsitstics: avoid sync load column which is skiped to analyze
Signed-off-by: Weizhen Wang <[email protected]>
1 parent aa9b6f4 commit bc9fb68

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/statistics/handle/syncload/stats_syncload.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err
300300
s.statsHandle.SPool().Put(se)
301301
}
302302
}()
303+
304+
skipTypes := sctx.GetSessionVars().AnalyzeSkipColumnTypes
303305
item := task.Item.TableItemID
304306
tbl, ok := s.statsHandle.Get(item.TableID)
305307

@@ -335,6 +337,10 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err
335337
// so we have to get the column info from the domain.
336338
wrapper.colInfo = tblInfo.Meta().GetColumnByID(item.ID)
337339
}
340+
_, skip := skipTypes[types.TypeToStr(col.Info.FieldType.GetType(), col.Info.FieldType.GetCharset())]
341+
if skip {
342+
return nil
343+
}
338344
// If this column is not analyzed yet and we don't have it in memory.
339345
// We create a fake one for the pseudo estimation.
340346
if loadNeeded && !analyzed {
@@ -348,6 +354,7 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err
348354
return nil
349355
}
350356
}
357+
failpoint.Inject("handleOneItemTaskPanic", nil)
351358
t := time.Now()
352359
needUpdate := false
353360
wrapper, err = s.readStatsForOneItem(sctx, item, wrapper, isPkIsHandle, task.Item.FullLoad)

pkg/statistics/handle/syncload/stats_syncload_test.go

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

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

0 commit comments

Comments
 (0)