diff --git a/store/helper/helper.go b/store/helper/helper.go index f24443433e724..8d584b216d9ad 100644 --- a/store/helper/helper.go +++ b/store/helper/helper.go @@ -653,11 +653,11 @@ func newTableWithKeyRange(db *model.DBInfo, table *model.TableInfo) TableInfoWit // NewIndexWithKeyRange constructs TableInfoWithKeyRange for given index, it is exported only for test. func NewIndexWithKeyRange(db *model.DBInfo, table *model.TableInfo, index *model.IndexInfo) TableInfoWithKeyRange { - return newIndexWithKeyRange(db, table, index) + return newIndexWithKeyRange(db, table, index, table.ID) } -func newIndexWithKeyRange(db *model.DBInfo, table *model.TableInfo, index *model.IndexInfo) TableInfoWithKeyRange { - sk, ek := tablecodec.GetTableIndexKeyRange(table.ID, index.ID) +func newIndexWithKeyRange(db *model.DBInfo, table *model.TableInfo, index *model.IndexInfo, physicalID int64) TableInfoWithKeyRange { + sk, ek := tablecodec.GetTableIndexKeyRange(physicalID, index.ID) startKey := bytesKeyToHex(codec.EncodeBytes(nil, sk)) endKey := bytesKeyToHex(codec.EncodeBytes(nil, ek)) return TableInfoWithKeyRange{ @@ -727,7 +727,13 @@ func (*Helper) GetTablesInfoWithKeyRange(schemas []*model.DBInfo) []TableInfoWit tables = append(tables, newTableWithKeyRange(db, table)) } for _, index := range table.Indices { - tables = append(tables, newIndexWithKeyRange(db, table, index)) + if table.Partition == nil || index.Global { + tables = append(tables, newIndexWithKeyRange(db, table, index, table.ID)) + continue + } + for _, partition := range table.Partition.Definitions { + tables = append(tables, newIndexWithKeyRange(db, table, index, partition.ID)) + } } } }