简体   繁体   中英

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. And at this moment, Neo4j does not support schema index on relationships. Then when I run query:

Match (n)-[r:typeX]->(m) return r;

Does it mean that in order to find this one relationship,
Neo4j has to iterate all the nodes/relationships (in millions) ?

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.

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. You basically have 2 options:

  1. Treat TYPE_X as thing within your domain and make it a node.
  2. use legacy indexes for relationships, see http://docs.neo4j.org/chunked/stable/indexing.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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