0
votes

I'm looking to satisfy a particular pattern with a query and then augment it with another query starting at one of the nodes from the first query. I believe I can do that with a query like this:

match (:p)-[:relationship]-(:x) optional match (:p)-[:relationship2]-(:x2)

Now suppose I put a limit at the end (e.g. Limit 200). Will the rows returned exhaust all of the optional matches that are satisfied before moving onto a new primary query with a new node p? Or is the query liable to arbitrarily return only a subset of the optional matches?

1

1 Answers

0
votes

1) Your Cypher pattern syntax seems to be bad. For a node (within parentheses) the optional identifier comes first and each optional label comes after a colon. For a relationship (within square brackets) the optional identifier comes first and the type comes after the colon. I suspect that your example should have looked something like this (so that the p identifier can be used to tie the 2 patterns together):

MATCH (p)-[relationship:FOO]-(x)
OPTIONAL MATCH (p)-[relationship2:BAR]-(x2)
...

2) The Cypher documentation does not define the behavior of LIMIT to the level of detail that you are asking about, so you should craft your Cypher to get a result that is as close as reasonable to what you want. For example, if you want to return up to 200 x2 values for a single p found by the MATCH pattern, you can use something like this:

MATCH (p)-[relationship:FOO]-(x)
WITH p LIMIT 1
OPTIONAL MATCH (p)-[relationship2:BAR]-(x2)
RETURN x2 LIMIT 200