Reputation: 4645
I'm using Neo4j 4.0.6 enterprise edition trying to do an indexed query to find max.
I've 5 million user nodes in this DB.
I've an index on tsScan:
CREATE INDEX user_scan for (u:User) on (u.tsScan)
Then I tried this:
match (u:User)
return u.id as id
order by u.tsScan
limit 100
It is taking a very long time time. About 3 minutes.
Since its a btree index, I expect that it should just pick the first 100 pointers in the pre sorted index.
Why does this take so long?
What do I have to do to be able to leverage the native-btree-1.0 index on u.tsScan ?
PS: This is running on a Mac with 16GB memory in the neo4j:4.0.6-enterprise docker container.
Upvotes: 0
Views: 125
Reputation: 6534
I would suggest you upgrade to the latest Neo4j version as there have been some upgrade to the order by operations from the 4.0.6 version. Also, there is a tiny bit of query optimization that you could make, it probably won't make a big difference, but it is still nice to implement it:
match (u:User)
WITH u
ORDER BY u.tsScan
LIMIT 100
RETURN u.id as id
This way you don't have to access the id property for all the users in your database, but you only access the id property for the resulted 100 users. Also, make sure to create an index on tsScan property.
Upvotes: 0