@@ -482,14 +482,32 @@ type RegionDetail struct {
482
482
func (rt * RegionDetail ) addTableInRange (dbName string , curTable * model.TableInfo , r * helper.RegionFrameRange ) {
483
483
tName := curTable .Name .String ()
484
484
tID := curTable .ID
485
-
485
+ pi := curTable . GetPartitionInfo ()
486
486
for _ , index := range curTable .Indices {
487
- if f := r .GetIndexFrame (tID , index .ID , dbName , tName , index .Name .String ()); f != nil {
488
- rt .Frames = append (rt .Frames , f )
487
+ if pi != nil {
488
+ for _ , def := range pi .Definitions {
489
+ if f := r .GetIndexFrame (def .ID , index .ID , dbName , fmt .Sprintf ("%s(%s)" , tName , def .Name .O ), index .Name .String ()); f != nil {
490
+ rt .Frames = append (rt .Frames , f )
491
+ }
492
+ }
493
+ } else {
494
+ if f := r .GetIndexFrame (tID , index .ID , dbName , tName , index .Name .String ()); f != nil {
495
+ rt .Frames = append (rt .Frames , f )
496
+ }
489
497
}
498
+
490
499
}
491
- if f := r .GetRecordFrame (tID , dbName , tName ); f != nil {
492
- rt .Frames = append (rt .Frames , f )
500
+
501
+ if pi != nil {
502
+ for _ , def := range pi .Definitions {
503
+ if f := r .GetRecordFrame (def .ID , dbName , fmt .Sprintf ("%s(%s)" , tName , def .Name .O )); f != nil {
504
+ rt .Frames = append (rt .Frames , f )
505
+ }
506
+ }
507
+ } else {
508
+ if f := r .GetRecordFrame (tID , dbName , tName ); f != nil {
509
+ rt .Frames = append (rt .Frames , f )
510
+ }
493
511
}
494
512
}
495
513
@@ -916,18 +934,43 @@ func (h tableHandler) handleStopScatterTableRequest(schema infoschema.InfoSchema
916
934
}
917
935
918
936
func (h tableHandler ) handleRegionRequest (schema infoschema.InfoSchema , tbl table.Table , w http.ResponseWriter , req * http.Request ) {
919
- tableID := tbl .Meta ().ID
920
- // for record
921
- startKey , endKey := tablecodec .GetTableHandleKeyRange (tableID )
922
- recordRegionIDs , err := h .RegionCache .ListRegionIDsInKeyRange (tikv .NewBackoffer (context .Background (), 500 ), startKey , endKey )
937
+ pi := tbl .Meta ().GetPartitionInfo ()
938
+ if pi != nil {
939
+ // Partitioned table.
940
+ var data []* TableRegions
941
+ for _ , def := range pi .Definitions {
942
+ tableRegions , err := h .getRegionsByID (tbl , def .ID , def .Name .O )
943
+ if err != nil {
944
+ writeError (w , err )
945
+ return
946
+ }
947
+
948
+ data = append (data , tableRegions )
949
+ }
950
+ writeData (w , data )
951
+ return
952
+ }
953
+
954
+ meta := tbl .Meta ()
955
+ tableRegions , err := h .getRegionsByID (tbl , meta .ID , meta .Name .O )
923
956
if err != nil {
924
957
writeError (w , err )
925
958
return
926
959
}
960
+
961
+ writeData (w , tableRegions )
962
+ }
963
+
964
+ func (h tableHandler ) getRegionsByID (tbl table.Table , id int64 , name string ) (* TableRegions , error ) {
965
+ // for record
966
+ startKey , endKey := tablecodec .GetTableHandleKeyRange (id )
967
+ recordRegionIDs , err := h .RegionCache .ListRegionIDsInKeyRange (tikv .NewBackoffer (context .Background (), 500 ), startKey , endKey )
968
+ if err != nil {
969
+ return nil , err
970
+ }
927
971
recordRegions , err := h .getRegionsMeta (recordRegionIDs )
928
972
if err != nil {
929
- writeError (w , err )
930
- return
973
+ return nil , err
931
974
}
932
975
933
976
// for indices
@@ -936,27 +979,23 @@ func (h tableHandler) handleRegionRequest(schema infoschema.InfoSchema, tbl tabl
936
979
indexID := index .Meta ().ID
937
980
indices [i ].Name = index .Meta ().Name .String ()
938
981
indices [i ].ID = indexID
939
- startKey , endKey := tablecodec .GetTableIndexKeyRange (tableID , indexID )
982
+ startKey , endKey := tablecodec .GetTableIndexKeyRange (id , indexID )
940
983
rIDs , err := h .RegionCache .ListRegionIDsInKeyRange (tikv .NewBackoffer (context .Background (), 500 ), startKey , endKey )
941
984
if err != nil {
942
- writeError (w , err )
943
- return
985
+ return nil , err
944
986
}
945
987
indices [i ].Regions , err = h .getRegionsMeta (rIDs )
946
988
if err != nil {
947
- writeError (w , err )
948
- return
989
+ return nil , err
949
990
}
950
991
}
951
992
952
- tableRegions := & TableRegions {
953
- TableName : tbl . Meta (). Name . O ,
954
- TableID : tableID ,
993
+ return & TableRegions {
994
+ TableName : name ,
995
+ TableID : id ,
955
996
Indices : indices ,
956
997
RecordRegions : recordRegions ,
957
- }
958
-
959
- writeData (w , tableRegions )
998
+ }, nil
960
999
}
961
1000
962
1001
// pdRegionStats is the json response from PD.
0 commit comments