简体   繁体   English

Neo4j查询对关系类型的效率

[英]Efficiency of Neo4j query on relationship type

Say I have a graph with millions of users, and millions relationships between them. 假设我有一个图,其中包含数百万个用户以及他们之间的数百万个关系。 But there is only one relationship of typeX exists in the graph. 但是图中仅存在typeX的一种关系。 And at this moment, Neo4j does not support schema index on relationships. 目前,Neo4j不支持关系的架构索引。 Then when I run query: 然后当我运行查询时:

Match (n)-[r:typeX]->(m) return r; 匹配(n)-[r:typeX]->(m)返回r;

Does it mean that in order to find this one relationship, 这是否意味着要找到这种关系,
Neo4j has to iterate all the nodes/relationships (in millions) ? Neo4j必须迭代所有节点/关系(以百万计)?

If that is the case, what can be done to improve it? 如果真是这样,该怎么做才能改善它? I don't like the idea of introducing extra nodes. 我不喜欢引入额外节点的想法。 First, there are things just naturally should be treated as relations. 首先,有些事情自然应该被视为关系。 say 'love', 'hate'. 说“爱”,“恨”。 Second, even if extra nodes have been added, queries like (a)-[*..5]->(b) may become much more complex. 其次,即使添加了额外的节点,诸如(a)-[* .. 5]->(b)之类的查询也可能变得更加复杂。

You're right that there are no relationship schema indexes. 您说对了,没有关系架构索引。 Typically anything being a "thing" in your domain should be a node. 通常,您域中所有属于“事物”的东西都应该是节点。 If you're looking for a single global TYPE_X relationship, it looks like being a thing in your domain. 如果您正在寻找一个单一的TYPE_X全局关系,那看起来就像是您的域中的事物。 You basically have 2 options: 您基本上有2个选择:

  1. Treat TYPE_X as thing within your domain and make it a node. 将TYPE_X视为您域中的事物并将其作为节点。
  2. use legacy indexes for relationships, see http://docs.neo4j.org/chunked/stable/indexing.html 使用旧索引建立关系,请参阅http://docs.neo4j.org/chunked/stable/indexing.html

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

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