# Best practices for queries that can take hours to complete

**URL:** <https://community.neo4j.com/t/best-practices-for-queries-that-can-take-hours-to-complete/58678>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated, cypher-tagged\
**Created:** [November 26, 2020, 3:21pm UTC](https://community.neo4j.com/t/best-practices-for-queries-that-can-take-hours-to-complete/58678 "2020-11-26T15:21:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marek\_kasle\_na](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/marek_kasle_na/32/14849_2.png) [@marek\_kasle\_na](https://community.neo4j.com/u/marek_kasle_na)\
**Post date:** [November 26, 2020, 3:21pm UTC](https://community.neo4j.com/t/best-practices-for-queries-that-can-take-hours-to-complete/58678/1 "2020-11-26T15:21:18Z")

</div>

What is the right way to execute and get results from a query that takes hours to process? Or is just Neo4j not built to do such things? Or is there some hidden timeout limit that silently kills such queries? Or do I need the enterprise edition?

Obviously running the query in browser and waiting for the result is out of the question.

I had some success with wrapping the query into apoc.export.cypher.query() and executing it locally through cypher-shell running in background using '&' on Linux as suggested here [Cypher-Shell - how to run testquery.cypher in background](https://community.neo4j.com/t/cypher-shell-how-to-run-testquery-cypher-in-background/16496). Works for queries taking e.g. 20 minutes but more demanding queries seems to just die silently without leaving any trace in the logs.

---

<div class="post-metadata">

**Author:** ![cuneyttyler](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cuneyttyler/32/27531_2.png) [@cuneyttyler](https://community.neo4j.com/u/cuneyttyler)\
**Post date:** [December 7, 2022, 5:14pm UTC](https://community.neo4j.com/t/best-practices-for-queries-that-can-take-hours-to-complete/58678/2 "2022-12-07T17:14:35Z")

</div>

If you don't need some fields in return don't return them it might greatly increase the time needed to return the values. Instead filter properties like this:

```auto
WITH keys(e) AS k1, e
UNWIND k1 AS k2
WITH e, k2 where k2 <> "relationship_string" and k2 <> "relationshipString" and RETURN id(e) AS entityId, k2 AS Prop,e[k2] AS Value

```

---

<div class="post-metadata">

**Author:** ![cuneyttyler](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cuneyttyler/32/27531_2.png) [@cuneyttyler](https://community.neo4j.com/u/cuneyttyler)\
**Post date:** [December 7, 2022, 5:16pm UTC](https://community.neo4j.com/t/best-practices-for-queries-that-can-take-hours-to-complete/58678/3 "2022-12-07T17:16:59Z")

</div>

Null check in neo4j is more expensive than 'not null' check. I am performing both on an indexed field and null check takes forever.
