Reputation: 2611
I am retrieving nodes the graph using the id. Once I get a node I am checking whether the node id is present in the list of id's I have. So, here I want to analyze the performance of the query in two ways:
i)Match and Retrieve
ii)Retrieve and Match
First Query:
MATCH (a{uid:4}) RETURN a
Second Query:
MATCH (a) WHERE a.uid in [1,2,3,4] RETURN a
In the first query, Am I retrieving the node when it match uid or else am I retrieving a node and then checking the uid is 4 or not, if not then dropping.
In the second query, I am retrieving the node and then checking whether the node id is present in the list, if yes, then I am returning.
Ambiguity in the functionality in the first query. What exactly happens with the first query?
Upvotes: 0
Views: 46
Reputation: 11705
You seem to imply the way the query is written defines an order between the operations, but it doesn't. Cypher is a declarative language: you say what you want, it takes care of the execution in the most optimal way possible. There is absolutely no difference between
MATCH (a {uid: 4}) RETURN a
and
MATCH (a) WHERE uid = 4 RETURN a
Both queries express your need to find a node by its uid
and the engine will do (as written) a full scan of the nodes to find those matching. If you add a label to the query, and you either have an index or a unicity constraint on uid
for that label, then the engine will do an index lookup.
MATCH (a) WHERE uid IN [1, 2, 3, 4] RETURN a
will also do a full scan, except the uid
will be checked against the list, whereas
CREATE CONSTRAINT ON (n:Node) ASSERT n.uid IS UNIQUE;
MATCH (a:Node) WHERE uid IN [1, 2, 3, 4] RETURN a
will do a multi-value index lookup.
Upvotes: 3