@@ -16,6 +16,7 @@ package lockstats
16
16
17
17
import (
18
18
"context"
19
+ "fmt"
19
20
20
21
"github.com/pingcap/errors"
21
22
"github.com/pingcap/tidb/domain"
@@ -51,12 +52,13 @@ func (e *LockExec) Next(_ context.Context, _ *chunk.Chunk) error {
51
52
is := do .InfoSchema ()
52
53
53
54
if e .onlyLockPartitions () {
54
- tableName := e .Tables [0 ]
55
- tid , pidNames , err := populatePartitionIDAndNames (tableName , tableName .PartitionNames , is )
55
+ table := e .Tables [0 ]
56
+ tid , pidNames , err := populatePartitionIDAndNames (table , table .PartitionNames , is )
56
57
if err != nil {
57
58
return err
58
59
}
59
60
61
+ tableName := fmt .Sprintf ("%s.%s" , table .Schema .L , table .Name .L )
60
62
msg , err := h .LockPartitions (tid , tableName , pidNames )
61
63
if err != nil {
62
64
return err
@@ -65,12 +67,12 @@ func (e *LockExec) Next(_ context.Context, _ *chunk.Chunk) error {
65
67
e .Ctx ().GetSessionVars ().StmtCtx .AppendWarning (errors .New (msg ))
66
68
}
67
69
} else {
68
- tids , pids , err := populateTableAndPartitionIDs (e .Tables , is )
70
+ tidAndNames , pidAndNames , err := populateTableAndPartitionIDs (e .Tables , is )
69
71
if err != nil {
70
72
return err
71
73
}
72
74
73
- msg , err := h .LockTables (tids , pids , e . Tables )
75
+ msg , err := h .LockTables (tidAndNames , pidAndNames )
74
76
if err != nil {
75
77
return err
76
78
}
@@ -97,15 +99,23 @@ func (*LockExec) Open(context.Context) error {
97
99
}
98
100
99
101
// populatePartitionIDAndNames returns the table ID and partition IDs for the given table name and partition names.
100
- func populatePartitionIDAndNames (tableName * ast.TableName , partitionNames []model.CIStr , is infoschema.InfoSchema ) (int64 , map [int64 ]string , error ) {
101
- tbl , err := is .TableByName (tableName .Schema , tableName .Name )
102
+ func populatePartitionIDAndNames (
103
+ table * ast.TableName ,
104
+ partitionNames []model.CIStr ,
105
+ is infoschema.InfoSchema ,
106
+ ) (int64 , map [int64 ]string , error ) {
107
+ if len (partitionNames ) == 0 {
108
+ return 0 , nil , errors .New ("partition list should not be empty" )
109
+ }
110
+ tbl , err := is .TableByName (table .Schema , table .Name )
102
111
if err != nil {
103
112
return 0 , nil , err
104
113
}
105
114
106
115
pi := tbl .Meta ().GetPartitionInfo ()
107
116
if pi == nil {
108
- return 0 , nil , errors .Errorf ("table %s is not a partition table" , tableName .Name )
117
+ return 0 , nil , errors .Errorf ("table %s is not a partition table" ,
118
+ fmt .Sprintf ("%s.%s" , table .Schema .L , table .Name .L ))
109
119
}
110
120
111
121
pidNames := make (map [int64 ]string , len (partitionNames ))
@@ -121,25 +131,36 @@ func populatePartitionIDAndNames(tableName *ast.TableName, partitionNames []mode
121
131
}
122
132
123
133
// populateTableAndPartitionIDs returns table IDs and partition IDs for the given table names.
124
- func populateTableAndPartitionIDs (tables []* ast.TableName , is infoschema.InfoSchema ) ([]int64 , []int64 , error ) {
125
- tids := make ([]int64 , 0 , len (tables ))
126
- pids := make ([]int64 , 0 )
134
+ func populateTableAndPartitionIDs (
135
+ tables []* ast.TableName ,
136
+ is infoschema.InfoSchema ,
137
+ ) (map [int64 ]string , map [int64 ]string , error ) {
138
+ if len (tables ) == 0 {
139
+ return nil , nil , errors .New ("table list should not be empty" )
140
+ }
141
+
142
+ tidAndNames := make (map [int64 ]string , len (tables ))
143
+ pidAndNames := make (map [int64 ]string , len (tables ))
127
144
128
145
for _ , table := range tables {
129
146
tbl , err := is .TableByName (table .Schema , table .Name )
130
147
if err != nil {
131
148
return nil , nil , err
132
149
}
133
- tids = append ( tids , tbl . Meta (). ID )
150
+ tidAndNames [ tbl . Meta (). ID ] = fmt . Sprintf ( "%s.%s" , table . Schema . L , table . Name . L )
134
151
135
152
pi := tbl .Meta ().GetPartitionInfo ()
136
153
if pi == nil {
137
154
continue
138
155
}
139
156
for _ , p := range pi .Definitions {
140
- pids = append ( pids , p .ID )
157
+ pidAndNames [ p . ID ] = genFullPartitionName ( table , p .Name . L )
141
158
}
142
159
}
143
160
144
- return tids , pids , nil
161
+ return tidAndNames , pidAndNames , nil
162
+ }
163
+
164
+ func genFullPartitionName (table * ast.TableName , partitionName string ) string {
165
+ return fmt .Sprintf ("%s.%s partition (%s)" , table .Schema .L , table .Name .L , partitionName )
145
166
}
0 commit comments