2
votes

I have simple node User that has UserId attribute which has unique constraint setup.

I started profiling my queries and noticed that every time I perform match against User node by UserId NodeByLabelScan performed instead of NodeUniqueIndexSeek.

I tried simplest match below.

match (u:User {UserId:"id"}) return u and index scan doesn't work.

If I specify index explicitly everything works fine.

match (u:User {UserId:"id"}) using index u:User(UserId) return u

Could anyone clarify why this happening.

1
How many User nodes do you have? It could be that the cost based query planner thinks/knows there are only few labeled nodes so no benefit of using the index. Can you try with the rule based planner (prepend CYPHER planner=rule to the Cypher query)? - albertoperdomo

1 Answers

8
votes

Cypher will use NodeUniqueIndexSeek by default if you have a certain amount of nodes of the same label, in 2.2.5 version it was triggered starting from 703 nodes if I remember.

Below this treshold, there is no performance improvement in the query by using the index or the labels index.