From 6180fb7358d216af3407a262cabb1b5ce322bd9f Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 15 Jan 2025 21:23:19 +0800 Subject: [PATCH] statistics: fix the panic when to async load stats with dropped index (#58887) close pingcap/tidb#58865 --- pkg/statistics/handle/storage/read.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/statistics/handle/storage/read.go b/pkg/statistics/handle/storage/read.go index e196152d2b..b32d1cff92 100644 --- a/pkg/statistics/handle/storage/read.go +++ b/pkg/statistics/handle/storage/read.go @@ -746,6 +746,10 @@ func loadNeededIndexHistograms(sctx sessionctx.Context, is infoschema.InfoSchema return nil } idxInfo := tblInfo.Meta().FindIndexByID(idx.ID) + if idxInfo == nil { + asyncload.AsyncLoadHistogramNeededItems.Delete(idx) + return errors.NotFoundf("index %d in table %d", idx.ID, idx.TableID) + } hg, err := HistogramFromStorageWithPriority(sctx, idx.TableID, idx.ID, types.NewFieldType(mysql.TypeBlob), hgMeta.NDV, 1, hgMeta.LastUpdateVersion, hgMeta.NullCount, hgMeta.TotColSize, hgMeta.Correlation, kv.PriorityHigh) if err != nil { return errors.Trace(err)