Add check for multiple all iterators

Update test to reflect that the two Alls will be collapsed,
also fix the test of tag optimization to use fixed iterators.
This commit is contained in:
Barak Michener 2015-08-12 14:50:57 -04:00
parent f54a84ff0b
commit ac1fa668e7
2 changed files with 51 additions and 3 deletions

View file

@ -292,12 +292,15 @@ func hasAnyNullIterators(its []graph.Iterator) bool {
// nothing, and graph.All which returns everything. Particularly, we want
// to see if we're intersecting with a bunch of graph.All iterators, and,
// if we are, then we have only one useful iterator.
//
// We already checked for hasAnyNullIteratators() -- so now we're considering
// All iterators.
func hasOneUsefulIterator(its []graph.Iterator) graph.Iterator {
usefulCount := 0
var usefulIt graph.Iterator
for _, it := range its {
switch it.Type() {
case graph.Null, graph.All:
case graph.All:
continue
case graph.Optional:
// Optional is weird -- it's not useful, but we can't optimize
@ -313,6 +316,10 @@ func hasOneUsefulIterator(its []graph.Iterator) graph.Iterator {
if usefulCount == 1 {
return usefulIt
}
if usefulCount == 0 {
// It's full of All iterators. We can safely return one of them.
return its[0]
}
return nil
}