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.

Fast way to MATCH multiple values for one variable of one label

When MATCH'ing on a single value the documentation is comprehensive and also suggests that:

MATCH (cid:Cid {contentID: '5ef78674-7631-11e4-a3cb-005056011aef')
RETURN cid
;

is faster / more efficient than

MATCH (cid:Cid)
WHERE cid.contentID = '5ef78674-7631-11e4-a3cb-005056011aef'
RETURN cid
;

What's the faster approach to inspecting many nodes for specific values, as in the query below? (each contentID is unique (constrained))

MATCH (cid:Cid)
WHERE cid.contentID IN ['5ef78674-7631-11e4-a3cb-005056011aef','5ef79922-7631-11e4-a3cb-005056011aef']
RETURN cid
;
5 REPLIES 5

There is no performance difference between the query with the property inline in the pattern vs in the WHERE clause. They should both generate the exact same query plan.

Your existing query using property membership IN a list is the right way to go. The only thing to recommend is that you have an index or unique constraint (whichever is appropriate) on :Cid(contentID)

Thanks for clarifying, Cid.contentID currently has a unique constraint. How do I decide whether a index or unique constraint is the preferred approach?

If the property is meant to be unique across all nodes of that label, then use a unique constraint (it will create an accompanying index for you automatically). If it's not unique but you'll be using it for frequent lookups of nodes of that label (like :Person nodes with a name property) then use an index.

ef78674-7631-11e4-a3cb-005056011aef what is this ? please explain

Can you please explain your question?  I don’t understand.