Skip to content

Using optimized cypher query when using filtering on relations #187

Closed
@Andy2003

Description

@Andy2003

Given the schema the schema

type Movie {
    id: ID
    title: String
    actorCount: Int
    genres: [Genre] @relation(name: "IN_GENRE", direction: OUT)
}
type Genre {
  name: String
  movies: [Movie] @relation(name: "IN_GENRE", direction: IN)
}

and the query:

{
    movie(where: { genres: { name: "some genre" } }) {
        actorCount
    }
}

this library is currently generating the following cypher:

MATCH (this:Movie)
WHERE EXISTS((this)-[:IN_GENRE]->(:Genre)) AND ALL(this_genres IN [(this)-[:IN_GENRE]->(this_genres:Genre) | this_genres] WHERE this_genres.name = $this_genres_name)
RETURN this { .actorCount } as this

The java version would instead generate:

MATCH (movie:Movie)
WHERE all(whereMovieGenreCond IN [(movie)-[:IN_GENRE]->(whereMovieGenre:Genre) | whereMovieGenre.name = $whereMovieGenreName] WHERE whereMovieGenreCond) RETURN movie { .actorCount } AS movie

According to @jexp:

Ours [The java version] is better as the planner is able to pull the condition into the expansion and doesn't have to build up a full list and post-filter

see also: neo4j-graphql/neo4j-graphql-java#220 (comment)

btw. in a further step we will migrate to subqueries, to improve the usage of the planner

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions