janusgraph
janusgraph copied to clipboard
Improve AdjacentVertexHasIdOptimizerStrategy
Currently AdjacentVertexHasIdOptimizerStrategy does not support hasContainers with more than 1 step
So next traversal not optimized
graph.traversal().V().hasId(P.within(1L)).bothE().otherV().hasId(2L).has('a','b').explain()
AdjacentVertexHasIdOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
AdjacentVertexFilterOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
AdjacentVertexIsOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
It cat be rewritten like this to utilize optimization
graph.traversal().V().hasId(P.within(1L)).bothE().otherV().is(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex.build().setId(2L).create()).has('w','w').explain()
AdjacentVertexHasUniquePropertyOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), IsStep(eq(v[2])), HasStep([w.eq(w)])]
AdjacentVertexHasIdOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), IsStep(eq(v[2])), HasStep([w.eq(w)])]
AdjacentVertexIsOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,edge), HasStep([~adjacent.eq(v[2])]), EdgeOtherVertexStep, HasStep([w.eq(w)])]
For simple cases AdjacentVertexHasIdOptimizerStrategy may extract hasId step from hasContainer