Reputation: 1108
Assuming a single company owns many branches and a branch by name only belongs to a single company. Say the number of branches is ~200 and the same branch name can exist for multiple companies so at most a few dozen branches using the same name.
Given that the branch name is indexed is it quicker to have Neo4J load the Branch nodes by name from the index and "figure it out" via the relationship to the company or is it better to pass the .name in the where clause? I tried to google this hierarchal arrangement and integration with indexing in the manual but this scenario eluded me and I'm sure someone super smart just knows.
start branch=node:branchIndex(name="some string"),
company=node(nodeId)
match company-[r:owns]->branch
return branch
start company = node(nodeId)
match company-[r:owns]->branch
where branch.name = "some string")
return branch
Upvotes: 1
Views: 75
Reputation: 6331
Well, an index lookup takes about 1000 times longer than traversing a property. For smaller traversals like (company)-[:owns]->(branch)
which will scan probably less then 1000 items I would say the WHERE clause is much cheaper than an index lookup.
In Neo4j 2.0 there will be sufficient statistics in the automatic indexes to only use WHERE, and from the query statistics be able to switch to index lookups automatically if they are more efficient.
Upvotes: 1