initial mongo indexed linksto

This commit is contained in:
Barak Michener 2015-04-18 19:55:39 -04:00
parent 6764ea0295
commit 5be1df3be3
9 changed files with 362 additions and 18 deletions

View file

@ -31,13 +31,15 @@ type And struct {
result graph.Value
runstats graph.IteratorStats
err error
qs graph.QuadStore
}
// Creates a new And iterator.
func NewAnd() *And {
func NewAnd(qs graph.QuadStore) *And {
return &And{
uid: NextUID(),
internalIterators: make([]graph.Iterator, 0, 20),
qs: qs,
}
}
@ -79,7 +81,7 @@ func (it *And) TagResults(dst map[string]graph.Value) {
}
func (it *And) Clone() graph.Iterator {
and := NewAnd()
and := NewAnd(it.qs)
and.AddSubIterator(it.primaryIt.Clone())
and.tags.CopyFrom(it)
for _, sub := range it.internalIterators {

View file

@ -78,7 +78,7 @@ func (it *And) Optimize() (graph.Iterator, bool) {
// The easiest thing to do at this point is merely to create a new And iterator
// and replace ourselves with our (reordered, optimized) clone.
newAnd := NewAnd()
newAnd := NewAnd(it.qs)
// Add the subiterators in order.
for _, sub := range its {
@ -95,6 +95,16 @@ func (it *And) Optimize() (graph.Iterator, bool) {
// the new And (they were unchanged upon calling Optimize() on them, at the
// start).
it.cleanUp()
// Ask the graph.QuadStore if we can be replaced. Often times, this is a great
// optimization opportunity (there's a fixed iterator underneath us, for
// example).
newReplacement, hasOne := it.qs.OptimizeIterator(newAnd)
if hasOne {
newAnd.Close()
return newReplacement, true
}
return newAnd, true
}