A query execution plan is the sequence of steps used to access data in a database management system.
PROFILE are the two Cypher instructions that will help us get the execution plan for a given Cypher query. EXPLAIN will provide you with the execution plan of your query without executing it, while PROFILE will execute the query and return results.
Using PROFILE is preferable for queries that are idempotent and aren't resource hungry as it gives more details like DB Hits and Page Cache Hits. We will be using PROFILE in the examples below. But the same steps apply to using EXPLAIN as well.
Fetching the Execution Plan
Parameters: If you wish to profile a parameterized query, declare the parameters in advance, using the
:param keyword. In this example, we will use a parameter named 'actName' with the value 'Hugo Weaving'
:param actName=>'Hugo Weaving';
Parameterized cypher query we wish to get the execution plan for:
WHERE keanu.name='Keanu Reeves' AND hugo.name=$actName
AND NOT (hugo)-[:ACTED_IN]->(movie)
Run the desired Cypher query by prefixing it with PROFILE.
Using Neo4j browser:
The 'Plan' tab in the results section will show the execution plan:
To produce the plans or run your queries you can use cypher-shell.
The execution plan will follow the query results:
Exporting the Execution Plan
If you need to share the execution plan with the technical support team, you will need to export this information.
From the Neo4j browser:
Use the 'Exports' button on the top right corner of the results pane and then export the plan in SVG using the 'Export SVG' option. While a PNG option is available, we recommend SVG exports as they can be zoomed to any size without losing their resolution.
Since the plan is displayed as plain text in cypher-shell, it can be copied and shared like any other text.
Note: Please ensure the plan is copied from the Plan name (Profile/Explain) till the last line of the plan.
The exact steps to copy selected text in the terminal will depend on the Operating System, and the terminal used to run cypher-shell.
Our Execution Plans manual can help you interpret the operations listed in the plan generated by EXPLAIN or PROFILE.