Neo4j Cypher查询优化 - 关系属性的APOC手册索引

时间:2018-04-29 09:53:10

标签: performance neo4j cypher neo4j-apoc

根据应用程序逻辑,我实现了自己的Cypher查询构建器,该构建器根据UI的用户输入创建复杂查询。

这是此类查询的示例:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = {decisionGroupId} 
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]-(filterCharacteristic2:Characteristic) 
WHERE filterCharacteristic2.id = 2 
WITH relationshipValueRel2, childD, dg 
WHERE   (ANY (id IN {relationshipValueRel21} WHERE id IN relationshipValueRel2.value ))  AND   ( relationshipValueRel2.`property.1.3` = {property2}  ) OR  ( relationshipValueRel2.`property.1.3` = {property3}  )  
WITH childD, dg  
MATCH (childD)-[relationshipValueRel3:HAS_VALUE_ON]-(filterCharacteristic3:Characteristic) 
WHERE filterCharacteristic3.id = 3 
WITH relationshipValueRel3, childD, dg 
WHERE   (relationshipValueRel3.`value` = 'London')  
WITH childD , dg  
SKIP 0 LIMIT 100 
WITH * 
MATCH (childD)-[ru:CREATED_BY]->(u:User) 
OPTIONAL MATCH (childD)-[rup:UPDATED_BY]->(up:User)  
RETURN ru, u, rup, up, childD AS decision, 
[ (dg)<-[:DEFINED_BY]-(entityGroup)-[:CONTAINS]->(entity)<-[:COMMENTED_ON]-(comg:CommentGroup)-[:COMMENTED_FOR]->(childD)
 | {entityId: toInt(entity.id),  types: labels(entity), totalComments: toInt(comg.totalComments)} ] AS commentGroups, 
[ (c1)<-[vg1:HAS_VOTE_ON]-(childD)
 | {criterionId: toInt(c1.id),  weight: vg1.avgVotesWeight, totalVotes: toInt(vg1.totalVotes)} ] AS weightedCriteria, 
[ (dg)<-[:DEFINED_BY]-(chg:CharacteristicGroup)-[rchgch1:CONTAINS]->(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD) 
 | {characteristicId: toInt(ch1.id),  v1:v1, optionIds: v1.optionIds, valueIds: v1.valueIds, value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, totalFlags: v1.totalFlags, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode} ] AS valuedCharacteristics

child:Decision的数量较少(例如<1000),它的工作速度非常快,但数据增长后性能明显下降。

这主要是基于关系属性的过滤操作,如:

WHERE (ANY (id IN {relationshipValueRel21} 
WHERE id IN relationshipValueRel2.value ))  
    AND ( relationshipValueRel2.`property.1.3` = {property2} ) 
    OR  ( relationshipValueRel2.`property.1.3` = {property3} ) 

请注意,这只是一个特例,基于用户输入的查询可以包含数十个这样的条件(<, <=, =, >, >=, IN, ALL IN, ANY IN)操作其中属性值可以是单个值或数组

现在我正在考虑如何提高此查询的性能,因为我预计会有数十或数十万child:Decision。为了做到这一点,我正在研究APOC Manual Index on Relationship Properties

考虑到这一点 - 重新实现我的查询构建器是否有意义,以便对上述过滤操作使用关系属性的APOC手册索引,否则它将无济于事?

0 个答案:

没有答案