6464 keys []interface {}
6565 expressions []string
6666 operations []* lookupOperation
67- indexes [] string
67+ indexes map [ string ] struct {}
6868 }
6969
7070 lookupOperation struct {
@@ -167,7 +167,7 @@ func (l *indexLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
167167}
168168
169169func (l * indexLookup ) Indexes () []string {
170- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
170+ return sortedIndexes ( l .indexes )
171171}
172172
173173// IsMergeable implements sql.Mergeable interface.
@@ -183,7 +183,9 @@ func (l *indexLookup) IsMergeable(lookup sql.IndexLookup) bool {
183183func (l * indexLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
184184 lookup := * l
185185 for _ , li := range lookups {
186- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
186+ for _ , idx := range li .Indexes () {
187+ lookup .indexes [idx ] = struct {}{}
188+ }
187189 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
188190 }
189191
@@ -194,7 +196,9 @@ func (l *indexLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup {
194196func (l * indexLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
195197 lookup := * l
196198 for _ , li := range lookups {
197- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
199+ for _ , idx := range li .Indexes () {
200+ lookup .indexes [idx ] = struct {}{}
201+ }
198202 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
199203 }
200204
@@ -205,7 +209,9 @@ func (l *indexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
205209func (l * indexLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
206210 lookup := * l
207211 for _ , li := range lookups {
208- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
212+ for _ , idx := range li .Indexes () {
213+ lookup .indexes [idx ] = struct {}{}
214+ }
209215 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
210216 }
211217
@@ -219,7 +225,7 @@ type filteredLookup struct {
219225 keys []interface {}
220226 expressions []string
221227 operations []* lookupOperation
222- indexes [] string
228+ indexes map [ string ] struct {}
223229
224230 reverse bool
225231 filter func (int , []byte ) (bool , error )
@@ -326,7 +332,7 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
326332}
327333
328334func (l * filteredLookup ) Indexes () []string {
329- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
335+ return sortedIndexes ( l .indexes )
330336}
331337
332338// IsMergeable implements sql.Mergeable interface.
@@ -341,7 +347,9 @@ func (l *filteredLookup) IsMergeable(lookup sql.IndexLookup) bool {
341347func (l * filteredLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
342348 lookup := * l
343349 for _ , li := range lookups {
344- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
350+ for _ , idx := range li .Indexes () {
351+ lookup .indexes [idx ] = struct {}{}
352+ }
345353 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
346354 }
347355
@@ -352,7 +360,9 @@ func (l *filteredLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLooku
352360func (l * filteredLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
353361 lookup := * l
354362 for _ , li := range lookups {
355- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
363+ for _ , idx := range li .Indexes () {
364+ lookup .indexes [idx ] = struct {}{}
365+ }
356366 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
357367 }
358368
@@ -363,7 +373,9 @@ func (l *filteredLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
363373func (l * filteredLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
364374 lookup := * l
365375 for _ , li := range lookups {
366- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
376+ for _ , idx := range li .Indexes () {
377+ lookup .indexes [idx ] = struct {}{}
378+ }
367379 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
368380 }
369381
@@ -388,7 +400,7 @@ type negateLookup struct {
388400 mapping * mapping
389401 keys []interface {}
390402 expressions []string
391- indexes [] string
403+ indexes map [ string ] struct {}
392404 operations []* lookupOperation
393405}
394406
@@ -501,7 +513,7 @@ func (l *negateLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
501513}
502514
503515func (l * negateLookup ) Indexes () []string {
504- return uniqueIndexes ( append ( l .indexes [:], l . id ) )
516+ return sortedIndexes ( l .indexes )
505517}
506518
507519// IsMergeable implements sql.Mergeable interface.
@@ -517,7 +529,9 @@ func (l *negateLookup) IsMergeable(lookup sql.IndexLookup) bool {
517529func (l * negateLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
518530 lookup := * l
519531 for _ , li := range lookups {
520- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
532+ for _ , idx := range li .Indexes () {
533+ lookup .indexes [idx ] = struct {}{}
534+ }
521535 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
522536 }
523537
@@ -528,7 +542,9 @@ func (l *negateLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup
528542func (l * negateLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
529543 lookup := * l
530544 for _ , li := range lookups {
531- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
545+ for _ , idx := range li .Indexes () {
546+ lookup .indexes [idx ] = struct {}{}
547+ }
532548 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
533549 }
534550
@@ -539,7 +555,9 @@ func (l *negateLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
539555func (l * negateLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
540556 lookup := * l
541557 for _ , li := range lookups {
542- lookup .indexes = append (lookup .indexes , li .Indexes ()... )
558+ for _ , idx := range li .Indexes () {
559+ lookup .indexes [idx ] = struct {}{}
560+ }
543561 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
544562 }
545563
@@ -748,13 +766,9 @@ func compare(a, b interface{}) (int, error) {
748766 }
749767}
750768
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 {
758772 result = append (result , idx )
759773 }
760774
0 commit comments