并行一度关系查询问题
我们的开发过程中有这样一个需求: A=[A1,A2,A3,…,An],B=[B1,B2,B3,…,Bm] 我需要查询A中的每个元素分别和B中每个元素是否有一度关系,并返回有关系的实体对。请问语句该怎么写效率最高
2 回复
可以参考这个查询,性能应该会有50%以上提升:
CALL apoc.cypher.parallel2(
'WITH $a AS a,$b AS b UNWIND a AS ale UNWIND b AS ble WITH ale,ble CALL apoc.cypher.run(\'MATCH (a:Person)-[r]-()-[*..3]-(b:Person) WHERE a.name={ale} AND b.name={ble} RETURN r LIMIT 1\',{ale:ale,ble:ble}) YIELD value WITH value.r AS r RETURN STARTNODE(r) AS sNode,ENDNODE(r) AS eNode',
{a:['Lilly Wachowski','Carrie-Anne Moss','Laurence Fishburne'],b:['Taylor Hackford','Al Pacino','Charlize Theron']},
'a'
)