Is there a way to show cypher execution plan?

后端 未结 2 1289
既然无缘
既然无缘 2020-11-29 11:16

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

相关标签:
2条回答
  • 2020-11-29 11:49

    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.

    0 讨论(0)
  • 2020-11-29 12:02

    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.

    0 讨论(0)
提交回复
热议问题