简体   繁体   English

neo4j中的cypher查询结果不一致

[英]Inconsistent cypher query results in neo4j

For illustrating this issue, create thousand nodes labeled z having incrementing numeric attribute zid. 为了说明此问题,请创建标记为z的千个节点,其中包含递增数字属性zid。

FOREACH (i IN range(1, 1000)| CREATE (z:z { zid: i }));

Now find a node using random zid value between 1 and 1000. 现在使用1到1000之间的随机zid值找到一个节点。

MATCH (n:z { zid: round(rand()*1000)}) 
RETURN n;

The above cypher returns inconsistent results, sometimes no nodes are returned, sometimes multiple nodes are returned. 上面的cypher返回不一致的结果,有时没有返回节点,有时会返回多个节点。

Tweaking the cypher as follows yields consistent results. 如下调整密码产生一致的结果。

WITH round(rand()*1000) AS x
MATCH (n:z { zid: x })
RETURN x, n;

What is wrong with the first cypher query ? 第一个密码查询有什么问题?

The reason why you are receiving inconsistent results with the first query has to do with how Neo4j evaluates Cypher queries. 您在第一个查询中收到不一致结果的原因与Neo4j如何评估Cypher查询有关。 The function round(rand()*1000) is evaluated for each of the items within the label index for z when using WHERE or concise syntax. 当使用WHERE或简明语法时,将为z的标签索引中的每个项评估函数round(rand()*1000) When you use the WITH clause, the function is evaluated once. 使用WITH子句时,该函数将被计算一次。

That being said, this looks like a bug that is specific to the rand() function. 话虽这么说,这看起来像是一个特定于rand()函数的bug。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM