diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index fd1ab1d12af00..f8bd44ea923c2 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -1694,6 +1694,7 @@ func keyColumnUsageInTable(schema *model.DBInfo, table *model.TableInfo) [][]typ } func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx sessionctx.Context) (err error) { + var extractorTableIDs []int64 tikvStore, ok := ctx.GetStore().(helper.Storage) if !ok { return errors.New("Information about TiKV region status can be gotten only when the storage is TiKV") @@ -1708,9 +1709,13 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx sessionctx.Context) ( if e.extractor != nil { extractor, ok := e.extractor.(*plannercore.TiKVRegionStatusExtractor) if ok && len(extractor.GetTablesID()) > 0 { - for _, tableID := range extractor.GetTablesID() { + extractorTableIDs = extractor.GetTablesID() + for _, tableID := range extractorTableIDs { regionsInfo, err := e.getRegionsInfoForTable(tikvHelper, is, tableID) if err != nil { + if errors.ErrorEqual(err, infoschema.ErrTableExists) { + continue + } return err } allRegionsInfo = allRegionsInfo.Merge(regionsInfo) @@ -1726,12 +1731,17 @@ func (e *memtableRetriever) setDataForTiKVRegionStatus(ctx sessionctx.Context) ( } tableInfos := tikvHelper.GetRegionsTableInfo(allRegionsInfo, is.AllSchemas()) for i := range allRegionsInfo.Regions { - tableList := tableInfos[allRegionsInfo.Regions[i].ID] - if len(tableList) == 0 { + regionTableList := tableInfos[allRegionsInfo.Regions[i].ID] + if len(regionTableList) == 0 { e.setNewTiKVRegionStatusCol(&allRegionsInfo.Regions[i], nil) } - for j := range tableList { - e.setNewTiKVRegionStatusCol(&allRegionsInfo.Regions[i], &tableList[j]) + for j := range regionTableList { + if len(extractorTableIDs) == 0 { + e.setNewTiKVRegionStatusCol(&allRegionsInfo.Regions[i], ®ionTableList[j]) + } + if slices.Contains(extractorTableIDs, regionTableList[j].Table.ID) { + e.setNewTiKVRegionStatusCol(&allRegionsInfo.Regions[i], ®ionTableList[j]) + } } } return nil