# How can I optimize my Cypher Queries?

**URL:** <https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114>\
**Category:** Cypher\
**Tags:** optimization, performance, cypher, knowledge-base\
**Created:** [July 17, 2018, 10:23pm UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114 "2018-07-17T22:23:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [July 17, 2018, 10:23pm UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/1 "2018-07-17T22:23:31Z")

</div>

What should I do if my Cypher query is slower than expected, or uses more memory or CPU than I have?

I'm running my queries with Neo4j Browser, copied from my application.

What should I do? Are there any good practices / pointers?

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [July 18, 2018, 12:00pm UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/2 "2018-07-18T12:00:11Z")

</div>

There are a number of things you can do:

1. Run your query with PROFILE or EXPLAIN. In the resulting **query plan** there are indications of expensive operations.
2. Make sure that lookup operations by id or value (numeric range, text search) run on fields that are indexed.
3. If you are running updates make sure that your updates handle batches of about 10k-100k records, if you have more, please batch them.

 ![query-plan](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/1X/9e1c7b3950bc71d99f1789baf8bcc26427396a79.png)

Share your queries and query plans (download and share the PNG) in this #Cypher category. Then others can help you.  
It is also helpful to share your data-model and other statistics, and also the actual Cypher query.

There are already a number of [performance related knowledge base posts](https://community.neo4j.com/search?expanded=true&q=tags%3Aperformance%2Cknowledge-base) available.

You can learn more here:

- [10 Cypher Tuning TIps GraphConnect Video](https://www.youtube.com/watch?v=DAlWoamQ41Q&list=PL9Hl4pk2FsvW-8xRSKjh9gWCYyJKpx0e6&index=40)
- [10 Cypher Tuning Tips Slides](https://www.slideshare.net/neo4j/top-10-cypher-tuning-tips-tricks)
- [Very useful Cypher tips & tricks presentation video](https://www.youtube.com/watch?v=BN5T8IimB78)
- [Query Tuning in Developer Manual](https://neo4j.com/docs/developer-manual/current/cypher/query-tuning/)
- [Execution Plan Explanation Developer Manual](https://neo4j.com/docs/developer-manual/current/cypher/execution-plans/)
- [Detailed Query Tuning Presentation](https://neo4j.com/blog/tuning-cypher-queries/)
- [Query Tuning Examples](https://neo4j.com/blog/neo4j-2-2-query-tuning/)
- [Batched Efficient Updates](https://medium.com/@mesirii/5-tips-tricks-for-fast-batched-updates-of-graph-structures-with-neo4j-and-cypher-73c7f693c8cc)
- [Efficient Loading of Subgraphs](https://medium.com/neo4j/loading-graph-data-for-an-object-graph-mapper-or-graphql-5103b1a8b66e)

Cheers, Michael

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [August 31, 2018, 9:28pm UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/3 "2018-08-31T21:28:45Z")

</div>



---

<div class="post-metadata">

**Author:** ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)\
**Post date:** [January 6, 2021, 4:04am UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/4 "2021-01-06T04:04:29Z")

</div>

Here's an interesting trick to optimize a query. It involves manually breaking up the query into two parts and forcing the part that winnows down the results be executed first returning a small result, and then executing a potentially slow query on the resulting small set.

> [@Slow query with very limited data and boolean = false](https://community.neo4j.com/t/slow-query-with-very-limited-data-and-boolean-false/31555):
>
> Hey all, I'm running up against an unexpectedly slow Cypher query, and I've looked into [several](https://community.neo4j.com/t/a-slow-running-cypher-query/13317) [other](https://medium.com/neo4j/cypher-query-optimisations-fe0539ce2e5c) posts but I'm still not sure what to do about my graph to make it more performant. In my query, I'm trying to find "unreserved" siblings of the origin node. Essentially, I want to walk up a :CHILD relationship to the (one) parent node, then find all of that parent's children that are not reserved. My data represents the structure of a document, which has nested levels: Title Subtitle Chapt…

---

<div class="post-metadata">

**Author:** ![clem](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/clem/32/4364_2.png) [@clem](https://community.neo4j.com/u/clem)\
**Post date:** [January 7, 2021, 10:48pm UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/5 "2021-01-07T22:48:52Z")

</div>

Here's a useful item on Relationships or Relationship Properties;

[http://www.dominickumar.com/blog/neo4j-relationship-modelling-performance/](http://www.dominickumar.com/blog/neo4j-relationship-modelling-performance/)

---

<div class="post-metadata">

**Author:** ![md7](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/md7/32/7618_2.png) [@md7](https://community.neo4j.com/u/md7)\
**Post date:** [February 9, 2021, 10:09am UTC](https://community.neo4j.com/t/how-can-i-optimize-my-cypher-queries/114/6 "2021-02-09T10:09:29Z")

</div>

Awesome, thats how traversing with index free adjacency.  
Just a small thought, even with having property on relationship along with manual index on relationship property (by using \*\*CALL db.index.fulltext.createRelationshipIndex)  
could you co-relate the performance metrics
