Neo4j: fastest way to find a node: by id function or index?
Asked Answered
A

2

7

Is it faster find a node by id function

MATCH (i:Item) WHERE id(i) = 2345 RETURN i

or by a property indexed?

MATCH (i:Item { name: "Foo"}) RETURN i

Profiling these queries I saw

  • id function: 2 total db hits
  • index: 1 total db hits
Aggravate answered 22/1, 2016 at 9:43 Comment(5)
Searching Indexes will always be faster than anything else but what is your Question?Pindaric
Is it find by id() faster than find by indexed property?Aggravate
Just keep in mind that ID() can be recycled, so if you store it as a reference somewhere else the reference might be orphanedLegroom
Thank you I know but this is not my case. Just in theory which is faster? I know for ex in orientdb the find by id is done in constant timeAggravate
If you made the query MATCH (i) WHERE id(i) = 2345 RETURN i (i.e. drop the label on (i:Item) it would be a single db hit too. It has the effect of removing the Filter step after the NodeByIdSeek step.Gombach
E
12

Find by id is always faster, as it directly points to the node-record.

Edulcorate answered 22/1, 2016 at 10:32 Comment(0)
H
0

Faster to search nodes by id. The function id() is deprecated. Use the function elementId() instead.

Holtz answered 22/5, 2024 at 8:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.