Reputation: 2611
I am working on a graph DB where an organisation contains 1 Billion Employee records. If I try to order the employees on their performance and get the top 1000 efficient employees, the query is not returning the results. How can I fine tune this.
My query:
MATCH (org:Organization{org_guid:"12345"})-[r:EMPLOYED_BY]-(emp:Employee)
WITH org,r,emp ORDER BY coalesce(r.efficiency,0) DESC
LIMIT (1000)
RETURN emp
Upvotes: 1
Views: 271
Reputation: 8546
Currently in Neo4j ODRER BY
is not able to use an index, which means it will require a scan, which can result in poor performance for large datasets.
There is an APOC procedure, however, that is able to use an index for range search and maintaining order. You would need to refactor your datamodel slightly as you cannot create an index on a relationship property. If instead you wanted to order by efficiency
as a property on :Employee
:
First, create an index on :Employee(efficiency)
:
CREATE INDEX ON :Employee(efficiency);
Then,
CALL apoc.index.orderedRange('Employee', 'efficiency', 0, 99999, false, 1000)
YIELD node AS employee
RETURN employee;
Another slight complication is that you want descending order, so you would need to store the negative of the efficiency value to get the results in descending order.
Upvotes: 1