44 "bytes"
55 "encoding/gob"
66 "io"
7+ "sort"
78 "strings"
89 "time"
910
6364 keys []interface {}
6465 expressions []string
6566 operations []* lookupOperation
67+ indexes map [string ]struct {}
6668 }
6769
6870 lookupOperation struct {
@@ -165,7 +167,7 @@ func (l *indexLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
165167}
166168
167169func (l * indexLookup ) Indexes () []string {
168- return [] string { l . id }
170+ return sortedIndexes ( l . indexes )
169171}
170172
171173// IsMergeable implements sql.Mergeable interface.
@@ -181,6 +183,9 @@ func (l *indexLookup) IsMergeable(lookup sql.IndexLookup) bool {
181183func (l * indexLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
182184 lookup := * l
183185 for _ , li := range lookups {
186+ for _ , idx := range li .Indexes () {
187+ lookup .indexes [idx ] = struct {}{}
188+ }
184189 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
185190 }
186191
@@ -191,6 +196,9 @@ func (l *indexLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup {
191196func (l * indexLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
192197 lookup := * l
193198 for _ , li := range lookups {
199+ for _ , idx := range li .Indexes () {
200+ lookup .indexes [idx ] = struct {}{}
201+ }
194202 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
195203 }
196204
@@ -201,6 +209,9 @@ func (l *indexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
201209func (l * indexLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
202210 lookup := * l
203211 for _ , li := range lookups {
212+ for _ , idx := range li .Indexes () {
213+ lookup .indexes [idx ] = struct {}{}
214+ }
204215 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
205216 }
206217
@@ -214,6 +225,7 @@ type filteredLookup struct {
214225 keys []interface {}
215226 expressions []string
216227 operations []* lookupOperation
228+ indexes map [string ]struct {}
217229
218230 reverse bool
219231 filter func (int , []byte ) (bool , error )
@@ -320,7 +332,7 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
320332}
321333
322334func (l * filteredLookup ) Indexes () []string {
323- return [] string { l . id }
335+ return sortedIndexes ( l . indexes )
324336}
325337
326338// IsMergeable implements sql.Mergeable interface.
@@ -335,6 +347,9 @@ func (l *filteredLookup) IsMergeable(lookup sql.IndexLookup) bool {
335347func (l * filteredLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
336348 lookup := * l
337349 for _ , li := range lookups {
350+ for _ , idx := range li .Indexes () {
351+ lookup .indexes [idx ] = struct {}{}
352+ }
338353 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
339354 }
340355
@@ -345,6 +360,9 @@ func (l *filteredLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLooku
345360func (l * filteredLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
346361 lookup := * l
347362 for _ , li := range lookups {
363+ for _ , idx := range li .Indexes () {
364+ lookup .indexes [idx ] = struct {}{}
365+ }
348366 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
349367 }
350368
@@ -355,6 +373,9 @@ func (l *filteredLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
355373func (l * filteredLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
356374 lookup := * l
357375 for _ , li := range lookups {
376+ for _ , idx := range li .Indexes () {
377+ lookup .indexes [idx ] = struct {}{}
378+ }
358379 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
359380 }
360381
@@ -379,6 +400,7 @@ type negateLookup struct {
379400 mapping * mapping
380401 keys []interface {}
381402 expressions []string
403+ indexes map [string ]struct {}
382404 operations []* lookupOperation
383405}
384406
@@ -491,7 +513,7 @@ func (l *negateLookup) Values(p sql.Partition) (sql.IndexValueIter, error) {
491513}
492514
493515func (l * negateLookup ) Indexes () []string {
494- return [] string { l . id }
516+ return sortedIndexes ( l . indexes )
495517}
496518
497519// IsMergeable implements sql.Mergeable interface.
@@ -507,6 +529,9 @@ func (l *negateLookup) IsMergeable(lookup sql.IndexLookup) bool {
507529func (l * negateLookup ) Intersection (lookups ... sql.IndexLookup ) sql.IndexLookup {
508530 lookup := * l
509531 for _ , li := range lookups {
532+ for _ , idx := range li .Indexes () {
533+ lookup .indexes [idx ] = struct {}{}
534+ }
510535 lookup .operations = append (lookup .operations , & lookupOperation {li , intersect })
511536 }
512537
@@ -517,6 +542,9 @@ func (l *negateLookup) Intersection(lookups ...sql.IndexLookup) sql.IndexLookup
517542func (l * negateLookup ) Union (lookups ... sql.IndexLookup ) sql.IndexLookup {
518543 lookup := * l
519544 for _ , li := range lookups {
545+ for _ , idx := range li .Indexes () {
546+ lookup .indexes [idx ] = struct {}{}
547+ }
520548 lookup .operations = append (lookup .operations , & lookupOperation {li , union })
521549 }
522550
@@ -527,6 +555,9 @@ func (l *negateLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {
527555func (l * negateLookup ) Difference (lookups ... sql.IndexLookup ) sql.IndexLookup {
528556 lookup := * l
529557 for _ , li := range lookups {
558+ for _ , idx := range li .Indexes () {
559+ lookup .indexes [idx ] = struct {}{}
560+ }
530561 lookup .operations = append (lookup .operations , & lookupOperation {li , difference })
531562 }
532563
@@ -596,7 +627,7 @@ func compare(a, b interface{}) (int, error) {
596627 return 0 , nil
597628 }
598629
599- if ! a {
630+ if a == false {
600631 return - 1 , nil
601632 }
602633
@@ -734,3 +765,13 @@ func compare(a, b interface{}) (int, error) {
734765 return 0 , errUnknownType .New (a )
735766 }
736767}
768+
769+ func sortedIndexes (indexes map [string ]struct {}) []string {
770+ var result = make ([]string , 0 , len (indexes ))
771+ for idx := range indexes {
772+ result = append (result , idx )
773+ }
774+
775+ sort .Strings (result )
776+ return result
777+ }
0 commit comments