Weekly Challenge #2 Query Tuning

For this week's challenge, let's create a recommendations sandbox at sandbox.neo4j.com.

This query returns the movie titles by a person who acted in the movies. We use the actorName parameter with the value "Clint Eastwood".

Your starting Cypher is

MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE a.name = $actor
RETURN m.title AS Movies

How can this query be improved?

Please post your solution below!

@Cobra ,
You cannot create the constraint on this dataset. And we want a query that uses the database as is without adding an index.
Your query had an elapsed time of 7 ms.
There is a query with an elapsed time of 5 ms.


Hello @TrevorS :blush:

Here is my query:

:param actor => 'Clint Eastwood';

MATCH (a:Actor {name: $actor}) 
MATCH (a)-[:ACTED_IN]->(m) 
RETURN m.title AS Movies;

Here is the screenshot:

Weekly Challenge #2.png

The query performance can be improved by adding a UNIQUE CONSTRAINT or an INDEX without changing the query:

CREATE CONSTRAINT constraint_Actor_name FOR (n:Actor) REQUIRE n.name IS UNIQUE;
CREATE INDEX index_Actor_name FOR (n:Actor) ON (n.name);


This query should be better:

MATCH (a:Person {name: $actor})-[:ACTED_IN]->(m)
RETURN m.title AS Movies;



@TrevorS My solution is the best I think: 30 ms:

PROFILE MATCH (a:Actor)-->(m:Movie)

WHERE exists ((a)-[:ACTED_IN]-()) AND a.name = "Clint Eastwood"

SET a:Actor

RETURN m.title


This query is not faster (even when I remove the update of the label).

A couple of things to note:
1. You do not want literals in your queries (except for testing a query). Use parameters.

2. Why are you setting the label? It is already an Actor?