Hi all,
Just checking whether my solution for exercise 5.12 would be considered equivalent to the solution the course provided?
My solution:
MATCH (m:Movie)<-[:DIRECTED]-(d:Person)
WITH count(d) AS numDirectors, m
WHERE numDirectors >= 2
OPTIONAL MATCH (m)<-[:REVIEWED]-(r:Person)
RETURN m.title, r.name
Provided solution:
MATCH (m:Movie)
WITH m, size((:Person)-[:DIRECTED]->(m)) AS directors
WHERE directors >= 2
OPTIONAL MATCH (p:Person)-[:REVIEWED]->(m)
RETURN m.title, p.name
Yes. They get the same results. I'd argue that your solution is more optimal. Looking at PROFILE and checking the performance, it's about twice as fast, albeit for a small database, and the PROFILE seems to points at the reasons for that - the initial query optimizes the path for a more constrained request. I found in various examples, the goal of their solutions were often to show neat ideas to keep in mind rather than "best practice". Keep it up!
Thanks for the feedback! Yeah, I think I've noticed it's not all supposed to be best practice although I wasn't aiming for better performance with this - just what came to mind first.