Chapter 8. Advanced Graph Patterns
This chapter explores advanced graph patterns that are useful to know as a Neo4j expert. The topics here touch on modeling techniques for security as well as entity resolution, more efficient queries, dealing with node degrees, and the more recent quantified path patterns. You’ve seen some usage of subqueries in previous chapters—now you’ll learn more about them.
To try the queries, continue using the chapter5 database, or, recreate it following the README in the GitHub repository.
Subqueries
Subqueries in Cypher are nested queries that execute within a nested scope of the outer query. The CALL subquery executes per row that arrives from the outer query. This is an important point: since the subquery operates in its own scope, it does not need to hold onto any data structures that were created while it executes over a row before it moves on to the next incoming row, thus reducing memory overhead. Subqueries are used both when reading from and writing to the graph.
CALL Subqueries
In Chapter 5, you imported a large set of data, which resulted in a graph with 18 million nodes and 100 million relationships. This graph is ideal to examine the effects of using a subquery. The first version of the query asks Neo4j to return every track in the graph along with the playlists that they’re on, and it uses a regular MATCH with path expansion:
//001-explain-all-tracks.cypher EXPLAIN MATCH (t:Track)-[:ON_PLAYLIST]->(p:Playlist) RETURN t as track, COLLECT(p) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access