cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Speed up initial node location without using labels

Sai_B
Node Link

To all the Graph enthusiasts,

Is there a way to speed up initial node location without using labels?
Hoping answer to my question.
Thanks in advance

1 ACCEPTED SOLUTION

Are you referring to the speed of looking up a node?

If you know the node's graph id, then you can look it up without knowing it's label:

MATCH (n)
WHERE id(n) = 12345
...

In the query plan you should see a NodeByIdSeek.

However these kinds of lookups tend to be rare, since you will rarely know the id of a node to lookup. And since ids of nodes and relationships can be reused (after deletion of the node or relationship), if you keep the ids outside of the database for later lookup, but don't keep it in sync with those deletions, then it could mean that a node lookup will instead get you a completely different node (since the one you wanted was previously deleted) or no node at all.

Otherwise, you'll need an index lookup, and all index lookups require that the node is labeled, and that the label of the index is present in the pattern used to find the node.

View solution in original post

2 REPLIES 2

Are you referring to the speed of looking up a node?

If you know the node's graph id, then you can look it up without knowing it's label:

MATCH (n)
WHERE id(n) = 12345
...

In the query plan you should see a NodeByIdSeek.

However these kinds of lookups tend to be rare, since you will rarely know the id of a node to lookup. And since ids of nodes and relationships can be reused (after deletion of the node or relationship), if you keep the ids outside of the database for later lookup, but don't keep it in sync with those deletions, then it could mean that a node lookup will instead get you a completely different node (since the one you wanted was previously deleted) or no node at all.

Otherwise, you'll need an index lookup, and all index lookups require that the node is labeled, and that the label of the index is present in the pattern used to find the node.

Sai_B
Node Link

Thanks for the help.