RCS
RCS

Reputation: 1432

Which is better way to filter in cypher query

I have a doubt about the optimization of cypher query while filtering. There is a relation between Entity and Address Node. Here is two query -

match(a:Address)<-[r]-(e:Entity) where a.addressLocation=~".*(?i)ABC XYZ.*" return r

match(e:Entity)-[r]->(a:Address) where a.addressLocation=~".*(?i)ABC XYZ.*" return r

Which is better among these above two query?

Upvotes: 2

Views: 71

Answers (1)

Evgen
Evgen

Reputation: 1338

Use command

profile match(a:Address)<-[r]-(e:Entity) where a.addressLocation=~".*(?i)ABC XYZ.*" return r
profile match(e:Entity)-[r]->(a:Address) where a.addressLocation=~".*(?i)ABC XYZ.*" return r

To see if there is any distinction in your version of neo in this two queries. Also I suggest that if you know that there is small number of Addresses with creteria a.addressLocation=~".*(?i)ABC XYZ.*" Try to use query like

 match(a:Address) where a.addressLocation=~".*(?i)ABC XYZ.*" 
 with a Match (a)<-[r]-(e:Entity) return r

To learn more about profiling look here http://neo4j.com/docs/stable/execution-plans.html

Upvotes: 1

Related Questions