Skip to content

Commit

Permalink
fix optimizer behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstruck committed Jan 5, 2019
1 parent db8bd49 commit aa2624c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
12 changes: 10 additions & 2 deletions engine/core/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/bmeg/grip/gripql"
"github.com/bmeg/grip/jsonpath"
"github.com/bmeg/grip/protoutil"
// log "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

// DefaultPipeline a set of runnable query operations
Expand Down Expand Up @@ -260,7 +260,9 @@ func (comp DefaultCompiler) Compile(stmts []*gripql.GraphStatement) (gdbi.Pipeli
}
}

log.Infof("Before optimizer: %+v", procs)
procs = indexStartOptimize(procs)
log.Infof("After optimizer: %+v", procs)

return &DefaultPipeline{procs, lastType, markTypes}, nil
}
Expand All @@ -272,7 +274,11 @@ func indexStartOptimize(pipe []gdbi.Processor) []gdbi.Processor {
var lookupV *LookupVerts
hasIDIdx := []int{}
hasLabelIdx := []int{}
isDone := false
for i, step := range pipe {
if isDone {
break
}
if i == 0 {
if lv, ok := step.(*LookupVerts); ok {
lookupV = lv
Expand All @@ -299,7 +305,7 @@ func indexStartOptimize(pipe []gdbi.Processor) []gdbi.Processor {
}
}
default:
break
isDone = true
}
}

Expand Down Expand Up @@ -338,6 +344,8 @@ func indexStartOptimize(pipe []gdbi.Processor) []gdbi.Processor {
if i == 0 {
continue
}
} else {
optimized = append(optimized, step)
}
if idOpt {
if i != hasIDIdx[0] {
Expand Down
34 changes: 33 additions & 1 deletion engine/core/optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,43 @@ func TestIndexStartOptimize(t *testing.T) {
&LookupVertexAdjOut{},
}
original := []gdbi.Processor{
&LookupVerts{ids: []string{"1", "2", "3"}},
&LookupVertexAdjOut{},
}
optimized := indexStartOptimize(original)
if !reflect.DeepEqual(optimized, expected) {
t.Log("actual", spew.Sdump(optimized))
t.Log("expected:", spew.Sdump(expected))
t.Error("indexStartOptimize returned an unexpected result")
}

expected = []gdbi.Processor{
&LookupVerts{},
&LookupVertexAdjOut{},
&HasID{ids: []string{"1", "2", "3"}},
}
original = []gdbi.Processor{
&LookupVerts{},
&LookupVertexAdjOut{},
&HasID{ids: []string{"1", "2", "3"}},
}
optimized := indexStartOptimize(original)
optimized = indexStartOptimize(original)
if !reflect.DeepEqual(optimized, expected) {
t.Log("actual", spew.Sdump(optimized))
t.Log("expected:", spew.Sdump(expected))
t.Error("indexStartOptimize returned an unexpected result")
}

expected = []gdbi.Processor{
&LookupVerts{ids: []string{"1", "2", "3"}},
&LookupVertexAdjOut{},
}
original = []gdbi.Processor{
&LookupVerts{},
&HasID{ids: []string{"1", "2", "3"}},
&LookupVertexAdjOut{},
}
optimized = indexStartOptimize(original)
if !reflect.DeepEqual(optimized, expected) {
t.Log("actual", spew.Sdump(optimized))
t.Log("expected:", spew.Sdump(expected))
Expand Down

0 comments on commit aa2624c

Please sign in to comment.