遵循我以前的问题: cypher 2.0 : using label based index to search a set of nodes
我正在尝试优化查询以查找用户常用组:
MATCH (gr:Group) <--(us:User)-->(gr2:Group)
WHERE gr.name = "gr1" or gr.name = "gr2"
return distinct gr2 as prop, count(distinct us ) as users
limit 10
不幸的是,大约需要4-5秒。 查询中的“配置文件”并获得以下结果:
ColumnFilter(symKeys=["prop", " INTERNAL_AGGREGATE074636fa-2950-4845-93ae-9d87da36e2b5"], returnItemNames=["prop", "users"], _rows=10, _db_hits=0)
Slice(limit="Literal(10)", _rows=10, _db_hits=0)
EagerAggregation(keys=["Cached(prop of type Node)"], aggregates=["( INTERNAL_AGGREGATE074636fa-2950-4845-93ae-9d87da36e2b5,Distinct(Count(us),us))"], _rows=10, _db_hits=0)
Extract(symKeys=["us", " UNNAMED20", "gr", "gr2", "r"], exprKeys=["prop"], _rows=34060, _db_hits=0)
Filter(pred="((Property(pr,name(1)) == Literal(gr1) OR Property(pr,name(1)) == Literal(gr2)) AND hasLabel(gr:Group(2)))", _rows=34060, _db_hits=68120)
SimplePatternMatcher(g="(us)-[' UNNAMED20']-(gr)", _rows=34060, _db_hits=1653118)
Filter(pred="hasLabel(gr2:Group(2))", _rows=28188, _db_hits=0)
TraversalMatcher(start={"label": "User", "producer": "NodeByLabel", "identifiers": ["us"]}, trail="(us)-[r WHERE hasLabel(NodeIdentifier():Group(2)) AND true]-(gr2)", _rows=28188, _db_hits=48828)
最多可达1653118 db_hits
但是以下查询只需要200毫秒:
MATCH (gr:Group) <--(us:User)-->(gr2:Group)
WHERE gr.name = "gr1" or gr.name = "gr2"
return distinct gr2 as prop
limit 10
并且,其简介:
Slice(limit="Literal(10)", _rows=10, _db_hits=0)
Distinct(_rows=10, _db_hits=0)
Extract(symKeys=["us", " UNNAMED20", "gr", "gr2", "r"], exprKeys=["prop"], _rows=17, _db_hits=0)
Filter(pred="((Property(gr,name(1)) == Literal(gr1) OR Property(gr,name(1)) == Literal(gr2)) AND hasLabel(gr:Group(2)))", _rows=17, _db_hits=34)
SimplePatternMatcher(g="(us)-[' UNNAMED20']-(gr)", _rows=17, _db_hits=600)
Filter(pred="hasLabel(gr2:Group(2))", _rows=10, _db_hits=0)
TraversalMatcher(start={"label": "User", "producer": "NodeByLabel", "identifiers": ["us"]}, trail="(us)-[r WHERE hasLabel(NodeIdentifier():Group(2)) AND true]-(gr2)", _rows=10, _db_hits=18)
顶部只有600 db_hits
有没有办法更改第一个查询以获得更好的性能相同的结果? 我只是不能接受每个查询性能4秒....
答案 0 :(得分:4)
是
MATCH (gr:Group)
WHERE gr.name = "gr1" or gr.name = "gr2"
WITH gr
MATCH (gr)<--(us:User)-->(gr2:Group)
return distinct gr2 as prop, count(distinct us ) as users
limit 10
更好吗?