Weekly Challenge #4 Movies with limited actors

Welcome back to our Weekly challenge series!
In keeping with the theme so far, this week's challenge is to tune the provided query.

Here's what you need to do!

  • Create a recommendations sandbox at sandbox.neo4j.com.
  • Here is a query that returns a row for every movie that has 2 or fewer actors. How can you make this query perform better?
"PROFILE
MATCH (m:Movie)<-[:ACTED_IN]-(a:Person)
WITH  m, collect(a.name) as actorNames
WHERE size(actorNames) <= $maxActors
RETURN  m.title, m.year, actorNames"

Solutions submitted between 8/30 and 9/9 will be eligible for a Neo4j T-Shirt drawing!

Show us your ways to improve the query!

Hello @TrevorS :blush:

:param maxActors => 2;

MATCH (m:Movie) 
WHERE 0 < size((m)<-[:ACTED_IN]-()) <= $maxActors 
RETURN m.title, m.year, [(m)<-[:ACTED_IN]-(a) | a.name] AS actorNames;

Cobra_0-1661876690501.png

Regards,
Cobra

size((m)<-[:ACTED_IN]-())

I don't think it's possible to beat that as suggested by @Cobra

Best I could do was 20,050 db hits haha, I believe adding the "0 < " is unnecessary right? For size to return < 0 wouldn't be possible? And it adds processing time (and somehow db hits?) so below is very very very barely faster :wink: hahah

MATCH (m:Movie)

WHERE size(()-[:ACTED_IN]->(m)) <= $maxActors

RETURN m.title, m.year, [(a)-[:ACTED_IN]->(m) | a.name]