Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-28-2021 05:14 PM
I fail to comprehend how Meg Ryan is excluded from the resulting list of the names of other:Person by this example cypher code given us in the subject lesson:
MATCH (meg:Person)-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(d:Person),
(other:Person)-[:ACTED_IN]->(m)
WHERE meg.name = 'Meg Ryan'
RETURN m.title as movie, d.name AS director , other.name AS co-actors
How (or why) does the query processor make the determination to exclude Meg Ryan from the expression (other:Person)-[:ACTED_IN]->(m)?
Coming from an SQL background, I fail to see why (other:Person)-[:ACTED_IN]->(m) implicitly excludes (meg:Person {name: 'Meg Ryan}).
I presume it is implicit, but would so love to read an explanation--perhaps a pointer to an clearly-written article explaining more fully the mechanics.
Thank you,
Tim
PS The lesson material immediately following, involving example using Val Kilmer, makes mention of relationships being traversed only once, rather than twice.
Is that where the answer lies? That an additional MATCH is needed if one wanted to see Meg Ryan? Is that the nature of MATCH, that it traverses every relationship only once?
06-29-2021 04:58 AM
Hello @palanquinpeacesoluti and welcome to the Community.
When you specify multiple patterns in a single MATCH clause, the query processor never traverses a relationship more than once. In this case the relationship between the Meg Ryan node and the movie nodes has already been traversed. So other will refer to all new nodes that have not been traversed to that movie.
Elaine
06-29-2021 02:38 PM
I commend your excellent answer. This is good to know with certainty and clarity.
I believe your one brief paragraph would add greatly to the lesson in question, perhaps following the figure depicting the Meg Ryan query's results. And then, one more brief remark contrasting the results, before or after the Val Kilmer example, might more fully illuminate this curricula text: "A best practice is to traverse as few nodes as possible so in this example, using multiple MATCH
patterns is best." Spaced repetition is such a great teacher!
Thank you again, Elaine, for answering my question so promptly and succinctly. Blessings!
10-02-2021 06:57 AM
In my case, I don't fully understand the last paragraph in the Val Kilmer example: " A best practice is to traverse as few nodes as possible so in this example, using multiple MATCH
patterns is best.".
Don't multiple patterns specified in one MATCH
traverse as few nodes as possible because the query processor never traverses a relationship more than once?
10-04-2021 07:31 AM
Hello @RaduTheMan,
Welcome to the Community!
What this is saying is that a single MATCH clause with 2 patterns is better than 2 MATCH clauses with patterns.
Elaine
10-04-2021 08:56 AM
Ok, thank you for your answer and for the greeting . In that phrase I thought that it reffers to multiple match clauses. I made a confusion, my bad.
All the sessions of the conference are now available online