问题描述
我有一个很长的Cypher查询(新的Neo4J 2.0版本),它使用MERGE命令创建了多个节点和连接.
I have a long Cypher query (the new Neo4J 2.0 version), which creates multiple nodes and connections using the MERGE command.
问题是:您认为我最好将其拆分为不同的部分,然后作为事务提交(出于健壮性考虑)还是我应该保留较长的单个文件(出于速度考虑)?
The question is: do you think I'm better off splitting it into different parts and submitting it as a transaction (for robustness) or should I keep the long single one (for speed)?
以下是查询:
MATCH (u:User {name: "User"}) MERGE (tag1:Hashtag {name:"tag1"}) MERGE (tag2:Hashtag
{name:"tag2"}) MERGE (tag3:Hashtag {name:"tag3"}) MERGE (tag4:Hashtag {name:"tag4"})
MERGE tag1-[:BY]->u MERGE tag2-[:BY]->u MERGE tag3-[:BY]->u MERGE tag4-[:BY]->u;
(我故意使请求更短,例如,假设有50个标签(节点)和更多的边)
(I purposefully made the request shorter, imagine that there are like 50 tags (nodes) and even more edges for example)
推荐答案
只要您的查询语句不是几百行,并且您创建的数据不超过5万个元素,我就会坚持使用一个查询.
As long as your query statement is not hundreds of lines and your data created doesn't exceed 50k elements, I'd stick with one query.
但是您应该改用参数.
But you should use parameters instead.
我还将使用foreach和参数重写您的查询
I would also rewrite your query with foreach and parameters
MATCH (u:User {name: {userName})
FOREACH (tagName in {tags} |
MERGE (tag:Hashtag {name:tagName})
MERGE (tag)-[:BY]->(u)
)
参数:
{userName:"User", tags: ["tag1",...,"tagN"]}
这篇关于对Neo4J Cypher 2.0中的多个节点/边缘创建提出一个MERGE请求,或者将其拆分为事务,是否更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!