From 0e6364f69b45b3e40a5fba89162c59bbfe3905f0 Mon Sep 17 00:00:00 2001 From: jiyfhust Date: Mon, 28 Nov 2022 14:32:00 +0800 Subject: [PATCH] store: fix tikv_region_status error information of partitioned table (#38743) close pingcap/tidb#38742 --- store/helper/helper.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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)) + } } } }