[英]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: 说明计划:
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. 这就是为什么您的查询需要这么长时间的原因。
You can try this query, which tells Cypher use the index on d
as well as n
. 您可以尝试执行此查询,该查询告诉Cypher使用
d
和n
上的索引。 (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.