这是更好地避免groovy collection methods,因为底层的图形数据库无法解释它们。它们存在于Traversal
之外。下面这个例子是像你:
gremlin> g.V().hasLabel("person").order().by('name',incr).explain()
==>Traversal Explanation
===============================================================================================================================
Original Traversal [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
ConnectiveStrategy [D] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
RepeatUnrollStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
InlineFilterStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
MatchPredicateStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
PathRetractionStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
IncidentToAdjacentStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
AdjacentToIncidentStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
FilterRankingStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
RangeByIsCountStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
TinkerGraphStepStrategy [P] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
ProfileStrategy [F] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
StandardVerificationStrategy [V] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
Final Traversal [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])]
当你做一个explain()
操作,你可以看到Traversal
外观底层图形数据库。如果在这种情况下数据库能够在order()
上进行优化,则可以利用该优势并且变得更高效。如果您只是简单地提交了g.V().hasLabel("person")
然后切换到groovy收集方法,那么底层数据库只会知道您正在尝试获取“人物”顶点列表,而不知道您还打算对它们进行排序(然后会在内存中发生使用groovy sort
)。