Accelerate `FetchRegionTableIndex` for `TIDB_HOT_REGIONS`
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
The current implementation of `FetchRegionTableIndex` is slow:
```
// FetchRegionTableIndex constructs a map that maps a table to its hot region information by the given raw hot RegionMetric metrics.
func (h *Helper) FetchRegionTableIndex(metrics map[uint64]RegionMetric, is infoschema.SchemaAndTable, filter func([]*model.DBInfo) []*model.DBInfo) ([]HotTableIndex, error) {
hotTables := make([]HotTableIndex, 0, len(metrics))
for regionID, regionMetric := range metrics {
...
f := h.FindTableIndexOfRegion(is, hotRange)
...
}
return hotTables, nil
}
// FindTableIndexOfRegion finds what table is involved in this hot region. And constructs the new frame item for future use.
func (*Helper) FindTableIndexOfRegion(is infoschema.SchemaAndTable, hotRange *RegionFrameRange) *FrameItem {
for _, dbInfo := range is.AllSchemas() {
tblInfos, _ := is.SchemaTableInfos(context.Background(), dbInfo.Name)
for _, tbl := range tblInfos {
if f := findRangeInTable(hotRange, dbInfo, tbl); f != nil {
return f
}
}
}
return nil
}
```
It'll fetch and decode all table infos for each region. We can have the following optimization:
1. Only fetch the needed schema for each range.
2. Cache the loaded schema temporarily.
The second optimization is relatively easy. The first one is much more challenging.
Contributor guide
Assessment
This issue has not been assessed yet.