我有以下查询使用普通关系操作进行节点过滤:
MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision)
WHERE dg.id = 1
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic)
WHERE filterCharacteristic2.id = 2
WITH relationshipValueRel2, childD, dg
WHERE (ANY (id IN [".NET"] WHERE id IN relationshipValueRel2.value ))
RETURN childD.name
只返回一个节点(正如预期的那样):
"Candidate1"
PROFILE输出:
我想优化查询性能,这就是为什么我使用以下触发器将关系添加到手动索引中的原因:
CALL apoc.trigger.add('HAS_VALUE_ON_ASSIGNED_RELATIONSHIP_PROPERTIES_TRIGGER', "UNWIND keys({assignedRelationshipProperties}) AS key
UNWIND {assignedRelationshipProperties}[key] AS map
WITH map
WHERE type(map.relationship) = 'HAS_VALUE_ON'
CALL apoc.index.addRelationship(map.relationship, keys(map.relationship)) RETURN true",
{phase:'before'})
和以下查询,以获取与第一个相同的数据,但仅来自手动索引:
MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision)
WHERE dg.id = 1
MATCH (childD)-[relationshipValueRel2:HAS_VALUE_ON]->(filterCharacteristic2:Characteristic)
WHERE filterCharacteristic2.id = 2
WITH relationshipValueRel2, filterCharacteristic2, childD, dg
CALL apoc.index.in(filterCharacteristic2,'HAS_VALUE_ON','(value:(".NET"))')
YIELD node WITH node AS childD
RETURN childD.name
但问题是,此查询返回同一节点的两个实例:
"Candidate1"
"Candidate1"
PROFILE输出:
我做错了什么以及为什么这个查询返回2个实例而不是单个实例?