@@ -18,6 +18,13 @@ import (
18
18
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
19
19
)
20
20
21
+ // partitionKey is used to group a partition's name and its index ID for
22
+ // indexing into a map.
23
+ type partitionKey struct {
24
+ indexID descpb.IndexID
25
+ name string
26
+ }
27
+
21
28
// GenerateSubzoneSpans constructs from a TableDescriptor the entries mapping
22
29
// zone config spans to subzones for use in the SubzoneSpans field of
23
30
// zonepb.ZoneConfig. SubzoneSpans controls which splits are created, so only
@@ -76,10 +83,11 @@ func GenerateSubzoneSpans(
76
83
a := & tree.DatumAlloc {}
77
84
78
85
subzoneIndexByIndexID := make (map [descpb.IndexID ]int32 )
79
- subzoneIndexByPartition := make (map [string ]int32 )
86
+ subzoneIndexByPartition := make (map [partitionKey ]int32 )
80
87
for i , subzone := range subzones {
81
88
if len (subzone .PartitionName ) > 0 {
82
- subzoneIndexByPartition [subzone .PartitionName ] = int32 (i )
89
+ partKey := partitionKey {indexID : descpb .IndexID (subzone .IndexID ), name : subzone .PartitionName }
90
+ subzoneIndexByPartition [partKey ] = int32 (i )
83
91
} else {
84
92
subzoneIndexByIndexID [descpb .IndexID (subzone .IndexID )] = int32 (i )
85
93
}
@@ -140,7 +148,8 @@ func GenerateSubzoneSpans(
140
148
}
141
149
var ok bool
142
150
if subzone := payloads [0 ].(zonepb.Subzone ); len (subzone .PartitionName ) > 0 {
143
- subzoneSpan .SubzoneIndex , ok = subzoneIndexByPartition [subzone .PartitionName ]
151
+ partKey := partitionKey {indexID : descpb .IndexID (subzone .IndexID ), name : subzone .PartitionName }
152
+ subzoneSpan .SubzoneIndex , ok = subzoneIndexByPartition [partKey ]
144
153
} else {
145
154
subzoneSpan .SubzoneIndex , ok = subzoneIndexByIndexID [descpb .IndexID (subzone .IndexID )]
146
155
}
@@ -165,7 +174,7 @@ func indexCoveringsForPartitioning(
165
174
tableDesc catalog.TableDescriptor ,
166
175
idx catalog.Index ,
167
176
part catalog.Partitioning ,
168
- relevantPartitions map [string ]int32 ,
177
+ relevantPartitions map [partitionKey ]int32 ,
169
178
prefixDatums []tree.Datum ,
170
179
) ([]covering.Covering , error ) {
171
180
if part .NumColumns () == 0 {
@@ -191,10 +200,11 @@ func indexCoveringsForPartitioning(
191
200
if err != nil {
192
201
return err
193
202
}
194
- if _ , ok := relevantPartitions [name ]; ok {
203
+ partKey := partitionKey {indexID : idx .GetID (), name : name }
204
+ if _ , ok := relevantPartitions [partKey ]; ok {
195
205
listCoverings [len (t .Datums )] = append (listCoverings [len (t .Datums )], covering.Range {
196
206
Start : keyPrefix , End : roachpb .Key (keyPrefix ).PrefixEnd (),
197
- Payload : zonepb.Subzone {PartitionName : name },
207
+ Payload : zonepb.Subzone {IndexID : uint32 ( idx . GetID ()), PartitionName : name },
198
208
})
199
209
}
200
210
newPrefixDatums := append (prefixDatums , t .Datums ... )
@@ -219,7 +229,8 @@ func indexCoveringsForPartitioning(
219
229
220
230
if part .NumRanges () > 0 {
221
231
err := part .ForEachRange (func (name string , from , to []byte ) error {
222
- if _ , ok := relevantPartitions [name ]; ! ok {
232
+ partKey := partitionKey {indexID : idx .GetID (), name : name }
233
+ if _ , ok := relevantPartitions [partKey ]; ! ok {
223
234
return nil
224
235
}
225
236
_ , fromKey , err := rowenc .DecodePartitionTuple (
@@ -232,10 +243,10 @@ func indexCoveringsForPartitioning(
232
243
if err != nil {
233
244
return err
234
245
}
235
- if _ , ok := relevantPartitions [name ]; ok {
246
+ if _ , ok := relevantPartitions [partKey ]; ok {
236
247
coverings = append (coverings , covering.Covering {{
237
248
Start : fromKey , End : toKey ,
238
- Payload : zonepb.Subzone {PartitionName : name },
249
+ Payload : zonepb.Subzone {IndexID : uint32 ( idx . GetID ()), PartitionName : name },
239
250
}})
240
251
}
241
252
return nil
0 commit comments