Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to show cypher execution plan?

Tags:

neo4j

cypher

I've seen a topic (Understanding Neo4j Cypher Profile keyword and execution plan) where profile keyword is mentioned.

I couldn't use it in Neo4j 2.0.0RC1 Community.

Peter wrote it's not fully implemented.

Will it ever be supported?

I mean, it could be interesting to watch the plan changes as we tune the query...

like image 889
gruby karol Avatar asked Dec 17 '13 07:12

gruby karol


People also ask

How do you optimize a Cypher query?

Each Cypher query gets optimized and transformed into an execution plan by the Cypher query planner. To minimize the resources used for this, try to use parameters instead of literals when possible. This allows Cypher to re-use your queries instead of having to parse and build new execution plans.

What is unwind in Cypher?

UNWIND expands a list into a sequence of rows. Introduction. Unwinding a list. Creating a distinct list. Using UNWIND with any expression returning a list.

What is a Cypher statement?

Cypher is a declarative graph query language that allows for expressive and efficient data querying in a property graph. Cypher was largely an invention of Andrés Taylor while working for Neo4j, Inc. (formerly Neo Technology) in 2011.

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.


2 Answers

You can still find the neo4j shell, where you can run the profile command.

Either by connecting to the running server by starting bin/neo4j-shell

Or by switching to the old web-ui in the "(i)" Info-menu on the left side and selecting the bottommost link "webadmin" -> http://localhost:7474/webadmin

Profiling information will be added to browser later on, when it is easier to read and understand.

like image 58
Michael Hunger Avatar answered Sep 19 '22 22:09

Michael Hunger


As of Neo4j 2.2 there are additional profiling facilities available. Some features that were only available via neo4j-shell or the REST endpoints are now available also in the Neo4j-browser, and some features are new altogether.

You can now use the PROFILE command with your cypher query directly in the Neo4j-browser repl to execute the query and see a visualization of the execution plan.

PROFILE
MATCH (n:Peter {foo: 'Paul'})
RETURN n.bar, ID(n)

-------------
n.bar   ID(n)
Mary    951

Cypher 2.2 profile

Additionally, you can now inspect a query plan without having to actually execute it, for instance to verify a query that would alter the database. Do so with the EXPLAIN command prepended to the query. See 15.2 How do I profile a query? from the documentation.

EXPLAIN
MATCH (n:Peter {foo: 'Paul'})
SET n.foo = 'Mary', n.bar = 'Paul'
RETURN n.foo, ID(n)

------------------------------------------
// Nothing returned, query is not executed

Cypher 2.2 explain

A related new feature is also the new 'cost based' query planner, as well as the ability to force the use of either the 'cost based' or the 'rule based' query planner for all queries or for any particular query. The documentation notes that not all queries may be solvable by the 'cost based' query planner, in which case the setting will be ignored and the 'rule based' planner used. See 15.1 How are queries executed?

To force the use of either query planner for all queries, set the query.planner.version configuration setting in conf/neo4j.properties (Neo4j server) or by calling the .setConfig() method on your GraphDatabaseService object (Neo4j embedded). Set it to COST or RULE, and to give the decision on which query planner to use back to Neo4j, set it to default (or remove the setting altogether). See 24.5 Configuration Settings, Starting an embedded database with configuration settings.

To force the use of either query planner for a particular query, prepend your query with CYPHER planner=cost or CYPHER planner=rule. See 15.1 How are queries executed?

CYPHER planner=cost
MATCH (n:Peter {foo: 'Paul'})
RETURN n.bar, ID(n)

You can PROFILE or EXPLAIN queries with either of the query planners and see any differences in how they implement your queries.

For help interpreting the execution plan, see the relevant chapter of the documentation, 16. Execution Plans.

like image 38
jjaderberg Avatar answered Sep 20 '22 22:09

jjaderberg