2016-09-30 33 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)。

相關問題