Fix linksto and zero-costs
This commit is contained in:
parent
e453385d5e
commit
a371155cd2
2 changed files with 23 additions and 14 deletions
|
|
@ -164,7 +164,7 @@ func (it *And) optimizeOrder(its []graph.Iterator) []graph.Iterator {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stats := f.Stats()
|
stats := f.Stats()
|
||||||
cost += stats.ContainsCost * (rootStats.Size / (stats.Size + 1))
|
cost += stats.ContainsCost * (1 + (rootStats.Size / (stats.Size + 1)))
|
||||||
}
|
}
|
||||||
cost *= rootStats.Size
|
cost *= rootStats.Size
|
||||||
if glog.V(3) {
|
if glog.V(3) {
|
||||||
|
|
@ -306,9 +306,12 @@ func hasOneUsefulIterator(its []graph.Iterator) graph.Iterator {
|
||||||
|
|
||||||
func materializeIts(its []graph.Iterator) []graph.Iterator {
|
func materializeIts(its []graph.Iterator) []graph.Iterator {
|
||||||
var out []graph.Iterator
|
var out []graph.Iterator
|
||||||
for _, it := range its {
|
|
||||||
|
allStats := getStatsForSlice(its)
|
||||||
|
out = append(out, its[0])
|
||||||
|
for _, it := range its[1:] {
|
||||||
stats := it.Stats()
|
stats := it.Stats()
|
||||||
if stats.Size*stats.NextCost < stats.ContainsCost {
|
if stats.Size*stats.NextCost < (stats.ContainsCost * (1 + (stats.Size / (allStats.Size + 1)))) {
|
||||||
if graph.Height(it, graph.Materialize) > 10 {
|
if graph.Height(it, graph.Materialize) > 10 {
|
||||||
out = append(out, NewMaterialize(it))
|
out = append(out, NewMaterialize(it))
|
||||||
continue
|
continue
|
||||||
|
|
@ -319,28 +322,34 @@ func materializeIts(its []graph.Iterator) []graph.Iterator {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// and.Stats() lives here in and-iterator-optimize.go because it may
|
func getStatsForSlice(its []graph.Iterator) graph.IteratorStats {
|
||||||
// in the future return different statistics based on how it is optimized.
|
primary := its[0]
|
||||||
// For now, however, it's pretty static.
|
primaryStats := primary.Stats()
|
||||||
func (it *And) Stats() graph.IteratorStats {
|
|
||||||
primaryStats := it.primaryIt.Stats()
|
|
||||||
ContainsCost := primaryStats.ContainsCost
|
ContainsCost := primaryStats.ContainsCost
|
||||||
NextCost := primaryStats.NextCost
|
NextCost := primaryStats.NextCost
|
||||||
Size := primaryStats.Size
|
Size := primaryStats.Size
|
||||||
for _, sub := range it.internalIterators {
|
for _, sub := range its[1:] {
|
||||||
stats := sub.Stats()
|
stats := sub.Stats()
|
||||||
NextCost += stats.ContainsCost * (primaryStats.Size / (stats.Size + 1))
|
NextCost += stats.ContainsCost * (1 + (primaryStats.Size / (stats.Size + 1)))
|
||||||
ContainsCost += stats.ContainsCost
|
ContainsCost += stats.ContainsCost
|
||||||
if Size > stats.Size {
|
if Size > stats.Size {
|
||||||
Size = stats.Size
|
Size = stats.Size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return graph.IteratorStats{
|
return graph.IteratorStats{
|
||||||
ContainsCost: ContainsCost * 2,
|
ContainsCost: ContainsCost,
|
||||||
NextCost: NextCost,
|
NextCost: NextCost,
|
||||||
Size: Size,
|
Size: Size,
|
||||||
Next: it.runstats.Next,
|
|
||||||
Contains: it.runstats.Contains,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// and.Stats() lives here in and-iterator-optimize.go because it may
|
||||||
|
// in the future return different statistics based on how it is optimized.
|
||||||
|
// For now, however, it's pretty static.
|
||||||
|
func (it *And) Stats() graph.IteratorStats {
|
||||||
|
stats := getStatsForSlice(it.SubIterators())
|
||||||
|
stats.Next = it.runstats.Next
|
||||||
|
stats.Contains = it.runstats.Contains
|
||||||
|
return stats
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,5 +212,5 @@ func (it *LinksTo) Stats() graph.IteratorStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LinksTo) Size() (int64, bool) {
|
func (it *LinksTo) Size() (int64, bool) {
|
||||||
return 0, true
|
return it.Stats().Size, false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue