Working with EXPLAIN
The EXPLAIN
clause returns a query execution plan as the database sees it. It does not actually execute the query and does not return data. It does not make any changes to the database itself. It can be used to easily identify missing indexes or query plans not using existing indexes, and so on. Also, it tells us how a query is traversing relationships to do its work.
Let’s look at a basic example of EXPLAIN
usage:
EXPLAIN MATCH (d {code:'313820'}) RETURN d
This query is trying to find a node with a code property matching the provided value. Notice that we did not provide a label in the query. This is intentional to showcase how a query plan can be used to identify issues.
We can see from the following screenshot that the first step we are doing is AllNodesScan
. What this means is that we are looking at the whole database to find the node we want and that we either have a mistake in the query or we are missing an index: