Reputation: 37369
My database has a two types of nodes: users and graphs. A user has access to a graph if there's a relationship (OWNS_GRAPH or HAS_ACCESS) between the graph and user. Simple enough. So using a Cypher query, there are two ways for me to search through graphs that the user has access to and I'm curious as to which one is more efficient.
The first way uses the relationships. So it's something along these lines:
START g=node:node_auto_index('type:graph AND ...'), u=node({id})
WHERE (u)-[:OWNS_GRAPH|HAS_ACCESS]->(g) RETURN g;
The second way involves using the unique ID I assign to every graph. Since I know which graphs a user has access to, I can make an array of those at runtime and use the IN
operator, like this:
START g=node:node_auto_index('type:graph AND ...')
WHERE g.id IN ["foo", "bar", "none"] RETURN g;
Obviously, I have to traverse the relationships still, just in Java instead of Cypher. But let's ignore that, since I can alleviate that problem with some clever ticks. Which query is more efficient? Traversing the relationships or using the array of IDs?
Upvotes: 0
Views: 61
Reputation: 19373
The first one (traversing on relationships) will be more efficient than a property lookup and compare.
Upvotes: 3