Skip to content

Commit

Permalink
executor: fix getting the more result when `select * from TIKV_REGION…
Browse files Browse the repository at this point in the history
…_STATUS where table_id=xx` (#38601)

close #37499
  • Loading branch information
Defined2014 authored Oct 23, 2022
1 parent 85b53e1 commit 41518c9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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], &regionTableList[j])
}
if slices.Contains(extractorTableIDs, regionTableList[j].Table.ID) {
e.setNewTiKVRegionStatusCol(&allRegionsInfo.Regions[i], &regionTableList[j])
}
}
}
return nil
Expand Down

0 comments on commit 41518c9

Please sign in to comment.