1
votes

In my scenario I have a few dozens of Cypher queries executed one after another. If any of them returns some data (reveals some knowledge), at the end of the loop the graph is changed accordingly and all the queries are executed again.

Currently I store all the queries as Strings. There are never more than 20 loops, but still having to parse all the queries every time seems a an overhead. Is there a way to optimize it, like by storing the queries in some precompiled state? Or there's nothing to worry about?

Any other hints that would make the above scenario work faster?

1
if you parameterize the queries then the execution plans will be cached - Dave Bennett
Without more details it's hard to tell if you could improve your queries. But I think if you store your queries as strings and run them again, there is nothing to worry about. There are no precompiled Cypher queries. - Martin Preusse

1 Answers

2
votes

As others have pointed out in the comments, you should use query parameters where possible. This has two benefits:

  1. You can reuse the queries in your code without having to parse / construct the strings given whatever values you want to include.
  2. Performance. The cypher compiler caches the execution plan for Cypher queries (ie queries it has seen before). If you use query parameters you will not incur the overhead of generating the query plan when executing the Cypher query again.

http://neo4j.com/docs/stable/cypher-parameters.html

http://neo4j.com/docs/stable/tutorials-cypher-parameters-java.html