2016-09-30 32 views
1

编写gremlin查询的最佳方式是通过groovy脚本或tinkerpop步骤吗?什么是编写gremlin查询的最好方法是通过groovy脚本或tinkerpop步骤

例如,根据加入日期对标签为Employee的一组顶点进行排序。

哪一种更好的检索方式?

是否

g.V().hasLabel('Employee').sort{a,b->a.value('DateOfJoining')<=>b.value('DateOfJoining')} 

g.V().hasLabel('Employee').order().by('DateOfJoining',incr) 

这里我用<=>运营商在Groovy脚本和我使用的TinkerPop有关平原为了一步第二个。

无论是查询的小鬼控制台工作,但他们中的哪一个是最好检索和如何的小鬼控制台解释这两种查询

回答

3

这是更好地避免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)。

相关问题