64
64
keys []interface {}
65
65
expressions []string
66
66
operations []* lookupOperation
67
- indexes [] string
67
+ indexes map [ string ] struct {}
68
68
}
69
69
70
70
lookupOperation struct {
@@ -167,7 +167,7 @@ func (l *indexLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
167
167
}
168
168
169
169
func (l * indexLookup ) Indexes () []string {
170
- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
170
+ return sortedIndexes ( l .indexes )
171
171
}
172
172
173
173
// IsMergeable implements sql.Mergeable interface.
@@ -183,7 +183,9 @@ func (l *indexLookup) IsMergeable(lookup sql.IndexLookup) bool {
183
183
func (l * indexLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
184
184
lookup := * l
185
185
for _ , li := range lookups {
186
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
186
+ for _ , idx := range li .Indexes () {
187
+ lookup .indexes [idx ] = struct {}{}
188
+ }
187
189
lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
188
190
}
189
191
@@ -194,7 +196,9 @@ func (l *indexLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup {
194
196
func (l * indexLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
195
197
lookup := * l
196
198
for _ , li := range lookups {
197
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
199
+ for _ , idx := range li .Indexes () {
200
+ lookup .indexes [idx ] = struct {}{}
201
+ }
198
202
lookup .operations = append (lookup .operations , & lookupOperation {li , union })
199
203
}
200
204
@@ -205,7 +209,9 @@ func (l *indexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
205
209
func (l * indexLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
206
210
lookup := * l
207
211
for _ , li := range lookups {
208
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
212
+ for _ , idx := range li .Indexes () {
213
+ lookup .indexes [idx ] = struct {}{}
214
+ }
209
215
lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
210
216
}
211
217
@@ -219,7 +225,7 @@ type filteredLookup struct {
219
225
keys []interface {}
220
226
expressions []string
221
227
operations []* lookupOperation
222
- indexes [] string
228
+ indexes map [ string ] struct {}
223
229
224
230
reverse bool
225
231
filter func (int , []byte ) (bool , error )
@@ -326,7 +332,7 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
326
332
}
327
333
328
334
func (l * filteredLookup ) Indexes () []string {
329
- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
335
+ return sortedIndexes ( l .indexes )
330
336
}
331
337
332
338
// IsMergeable implements sql.Mergeable interface.
@@ -341,7 +347,9 @@ func (l *filteredLookup) IsMergeable(lookup sql.IndexLookup) bool {
341
347
func (l * filteredLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
342
348
lookup := * l
343
349
for _ , li := range lookups {
344
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
350
+ for _ , idx := range li .Indexes () {
351
+ lookup .indexes [idx ] = struct {}{}
352
+ }
345
353
lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
346
354
}
347
355
@@ -352,7 +360,9 @@ func (l *filteredLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLooku
352
360
func (l * filteredLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
353
361
lookup := * l
354
362
for _ , li := range lookups {
355
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
363
+ for _ , idx := range li .Indexes () {
364
+ lookup .indexes [idx ] = struct {}{}
365
+ }
356
366
lookup .operations = append (lookup .operations , & lookupOperation {li , union })
357
367
}
358
368
@@ -363,7 +373,9 @@ func (l *filteredLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
363
373
func (l * filteredLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
364
374
lookup := * l
365
375
for _ , li := range lookups {
366
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
376
+ for _ , idx := range li .Indexes () {
377
+ lookup .indexes [idx ] = struct {}{}
378
+ }
367
379
lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
368
380
}
369
381
@@ -388,7 +400,7 @@ type negateLookup struct {
388
400
mapping * mapping
389
401
keys []interface {}
390
402
expressions []string
391
- indexes [] string
403
+ indexes map [ string ] struct {}
392
404
operations []* lookupOperation
393
405
}
394
406
@@ -501,7 +513,7 @@ func (l *negateLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
501
513
}
502
514
503
515
func (l * negateLookup ) Indexes () []string {
504
- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
516
+ return sortedIndexes ( l .indexes )
505
517
}
506
518
507
519
// IsMergeable implements sql.Mergeable interface.
@@ -517,7 +529,9 @@ func (l *negateLookup) IsMergeable(lookup sql.IndexLookup) bool {
517
529
func (l * negateLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
518
530
lookup := * l
519
531
for _ , li := range lookups {
520
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
532
+ for _ , idx := range li .Indexes () {
533
+ lookup .indexes [idx ] = struct {}{}
534
+ }
521
535
lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
522
536
}
523
537
@@ -528,7 +542,9 @@ func (l *negateLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup
528
542
func (l * negateLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
529
543
lookup := * l
530
544
for _ , li := range lookups {
531
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
545
+ for _ , idx := range li .Indexes () {
546
+ lookup .indexes [idx ] = struct {}{}
547
+ }
532
548
lookup .operations = append (lookup .operations , & lookupOperation {li , union })
533
549
}
534
550
@@ -539,7 +555,9 @@ func (l *negateLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
539
555
func (l * negateLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
540
556
lookup := * l
541
557
for _ , li := range lookups {
542
- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
558
+ for _ , idx := range li .Indexes () {
559
+ lookup .indexes [idx ] = struct {}{}
560
+ }
543
561
lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
544
562
}
545
563
@@ -748,13 +766,9 @@ func compare(a, b interface{}) (int, error) {
748
766
}
749
767
}
750
768
751
- func uniqueIndexes (indexes []string ) []string {
752
- var m = make (map [string ]struct {})
753
- for _ , idx := range indexes {
754
- m [idx ] = struct {}{}
755
- }
756
- var result = make ([]string , 0 , len (m ))
757
- for idx := range m {
769
+ func sortedIndexes (indexes map [string ]struct {}) []string {
770
+ var result = make ([]string , 0 , len (indexes ))
771
+ for idx := range indexes {
758
772
result = append (result , idx )
759
773
}
760
774
0 commit comments