简体   繁体   English

检查两个节点是否在恒定时间内有关系

[英]Check if two nodes have a relationship in constant time

Currently I have a unique index on node with label "d:ReferenceEntity". 目前,我在带有标签“ d:ReferenceEntity”的节点上具有唯一索引。 It's taking approximately 11 seconds for this query to run, returning 7 rows. 该查询运行大约需要11秒钟,返回7行。 Granted T1 has about 400,000 relationships. 授予的T1有大约40万个关系。

I'm not sure why this would take too long, considering we can build a Map of all connected Nodes to T1, thus giving constant time. 考虑到我们可以建立所有连接到T1的节点的Map,因此我不知道为什么会花这么长时间,因此可以提供恒定的时间。

Am I missing some other index features that Neo4j can provide? 我是否缺少Neo4j可以提供的其他一些索引功能? Also my entire dataset is in memory, so it shouldn't have anything with going to disk. 而且我的整个数据集都在内存中,因此它不应该存入磁盘。

match(n:ReferenceEntity {entityId : "T1" })-[r:HAS_REL]-(d:ReferenceEntity) WHERE d.entityId in ["T2", "T3", "T4"] return n


:schema
 Indexes
  ON :ReferenceEntity(entityId) ONLINE (for uniqueness constraint) 

 Constraints
  ON (referenceentity:ReferenceEntity) ASSERT referenceentity.entityId IS UNIQUE

Explain Plan: 说明计划:

解释计划

  1. You had used EXPLAIN instead of PROFILE to get that query plan, so it shows misleading estimated row counts. 您已使用EXPLAIN而不是PROFILE来获取该查询计划,因此它显示了误导的估计行数。 If you had used PROFILE , then the Expand(All) operation actually would have had about 400,000 rows, since that operation would actually iterate through every relationship. 如果使用过PROFILE ,那么Expand(All)操作实际上将有大约40万行,因为该操作实际上将遍历每个关系。 That is why your query takes so long. 这就是为什么您的查询需要这么长时间的原因。

  2. You can try this query, which tells Cypher use the index on d as well as n . 您可以尝试执行此查询,该查询告诉Cypher使用dn上的索引。 (On my machine, I had to use the USING INDEX clause twice to get the desired results.) It definitely pays to use PROFILE to tune Cypher code. (在我的机器上,我必须两次使用USING INDEX子句才能获得所需的结果。)使用PROFILE调整Cypher代码肯定是值得的。

     MATCH (n:ReferenceEntity { entityId : "T1" }) USING INDEX n:ReferenceEntity(entityId) MATCH n-[r:HAS_REL]-(d:ReferenceEntity) USING INDEX d:ReferenceEntity(entityId) WHERE d.entityId IN ["T2", "T3", "T4"] RETURN n, d; 

    Here is the Profile Plan (In my DB, I had 2 relationships that satisfy the WHERE test): 这是配置文件计划(在我的数据库中,我有2个满足WHERE测试的关系):

轮廓图

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

相关问题 在java中的neo4j嵌入式数据库中,我应该如何检查两个节点是否相互关联? - How should I check if two nodes have relationship with each other,in neo4j embedded database in java? 如何在单个数据库事务/查询中检查两个节点之间是否存在关系? - How to check if there is a relationship between two nodes in a single DB transaction/Query? 对依赖两个节点的关系进行建模 - Modeling a relationship that relies on two nodes 图数据库两个节点只有在两者都为真时才与另一个节点有关系 - Graph database two nodes have a relationship with another node ONLY if both are true 如何查找两个日期时间之间新添加/修改的节点/关系 - How to find newly added/modified nodes/relationship between two date-time 仅显示关系中具有特定属性的节点 - Only show nodes that have a specific properties in relationship 在两个先前断开的节点之间创建关系 - Creating relationship between two previously disconnected nodes 为一组节点创建每两个节点之间的关系 - Create relationship between each two nodes for a set of nodes 如何返回neo4j中具有一定关系的节点,然后返回与第一个节点具有不同关系的节点? - How do I return nodes in neo4j that have a certain relationship, and then return nodes that have a different relationship with the first nodes? 检查邻居是否有连接节点的子集 - Check if Neighbors have subset of connected nodes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM