diff --git a/pkg/statistics/handle/syncload/stats_syncload.go b/pkg/statistics/handle/syncload/stats_syncload.go index bbee5713b92fc..cd4395f9ec2ae 100644 --- a/pkg/statistics/handle/syncload/stats_syncload.go +++ b/pkg/statistics/handle/syncload/stats_syncload.go @@ -300,6 +300,8 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err s.statsHandle.SPool().Put(se) } }() + + skipTypes := sctx.GetSessionVars().AnalyzeSkipColumnTypes item := task.Item.TableItemID tbl, ok := s.statsHandle.Get(item.TableID) @@ -335,6 +337,10 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err // so we have to get the column info from the domain. wrapper.colInfo = tblInfo.Meta().GetColumnByID(item.ID) } + _, skip := skipTypes[types.TypeToStr(col.Info.FieldType.GetType(), col.Info.FieldType.GetCharset())] + if skip { + return nil + } // If this column is not analyzed yet and we don't have it in memory. // We create a fake one for the pseudo estimation. if loadNeeded && !analyzed { @@ -348,6 +354,7 @@ func (s *statsSyncLoad) handleOneItemTask(task *statstypes.NeededItemTask) (err return nil } } + failpoint.Inject("handleOneItemTaskPanic", nil) t := time.Now() needUpdate := false wrapper, err = s.readStatsForOneItem(sctx, item, wrapper, isPkIsHandle, task.Item.FullLoad) diff --git a/pkg/statistics/handle/syncload/stats_syncload_test.go b/pkg/statistics/handle/syncload/stats_syncload_test.go index 0610af3f1a415..43c5dfd815ad5 100644 --- a/pkg/statistics/handle/syncload/stats_syncload_test.go +++ b/pkg/statistics/handle/syncload/stats_syncload_test.go @@ -55,6 +55,22 @@ func TestSyncLoadSkipUnAnalyzedItems(t *testing.T) { failpoint.Disable("github.com/pingcap/tidb/pkg/statistics/handle/syncload/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)