假设我的应用程序场景如下:
JOJO家族的每个成员都是以他的祖先的名字命名的。第一代叫乔纳森,所以乔纳森的直系后裔叫做JonathanJoseph和JonathanGiorno。等等,我们得到了JonathanJosephJotaro,JonathanJosephJosuke,JonathanJosephJotaroJolyne。
(Jonathan)-[:AncestorOf]->(JonathanJoseph)
(Jonathan)-[:AncestorOf]->(JonathanGiorno)
(JonathanJoseph)-[:AncestorOf]->(JonathanJosephJotaro)
(JonathanJoseph)-[:AncestorOf]->(JonathanJosephJosuke)
(JonathanJosephJotaro)-[:AncestorOf]->(JonathanJosephJotaroJolyne)JOJO家族继承了一代又一代的黄金精神,所以每个人都有一种特殊的能力,叫做“站立力”。但是,我们只关心叶节点(没有后代)上的JOJO的“站立能力”。
(JonathanGiorno)-[:Owns]->(Gold Experience)
(JonathanJosephJosuke)-[:Owns]->(Crazy Diamond)
(JonathanJosephJotaroJolyne)-[:Owns]->(Stone Free)问题是:
,
。
- Not store any ancestor nodes, use START WITH to get the matched leaf nodes MATCH (j:JOJO)-[:Owns]->(sp:StandPower) WHERE j.name STARTS WITH "Jonathan" return sp哪种解决方案更好?
的情况仍然是这样吗?
发布于 2022-02-23 13:31:05
根据索引偏好的这一链接:
https://neo4j.com/docs/cypher-manual/current/query-tuning/indexes/#_index_preference
引用:
恩古特:
因此,在您的例子中,我将使用
MATCH (:JOJO{name:"Jonathan"})-[:AncestorOf*]-(:JOJO)-[:Owns]->(sp:StandPower)
return sp通常,由于字符串匹配已经在使用索引,所以执行字符串匹配将从执行开始。如果您执行查询计划来查看如何使用索引的详细信息,那么情况要好得多。
https://stackoverflow.com/questions/71230702
复制相似问题