0
votes

At the moment I have the following cypher query:

MATCH (co1:CORPORATION)<-[:is_employee_of]-(p:PERSON)-[:has_personal_account]->(a1:ACCOUNT)- 
[:transfer_origin]->(t:TRANSFER)<-[:transfer_destination]-(a2:ACCOUNT)<-[:has_corporate_account]- 
(co2:CORPORATION)-[:incorporated_in]->(c:COUNTRY)
WHERE c.IS_TAX_HAVEN = 1
RETURN co1

This query has a lot of relationships and nodes in the MATCH. Is this the right way to write a query or do I have to split up this MATCH?

1
What do you want to achieve?Tomaž Bratanič

1 Answers

1
votes

With respect to performance, your specific MATCH pattern probably does not need to be split up. However, for better (human) readability, you may want to split it up anyway -- the Cypher parser would generally produce the same execution plan either way.

As an example, your query could start with a shorter MATCH pattern that is easier to understand and is more closely tied to the WHERE clause:

MATCH (a2:ACCOUNT)<-[:has_corporate_account]-(:CORPORATION)-[:incorporated_in]->(c:COUNTRY)
WHERE c.IS_TAX_HAVEN = 1
MATCH
  (a1:ACCOUNT)-[:transfer_origin]->(:TRANSFER)<-[:transfer_destination]-(a2),
  (co1:CORPORATION)<-[:is_employee_of]-(:PERSON)-[:has_personal_account]->(a1)
RETURN DISTINCT co1

Note that this query returns DISTINCT co1, to ensure that the same corporation is not returned more than once.