# Performance issues with simple match on small graph (lineage analysis, cypher doesn't terminate)

**URL:** <https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [November 21, 2022, 2:57pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022 "2022-11-21T14:57:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![harmonie\_shorts](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@harmonie\_shorts](https://community.neo4j.com/u/harmonie_shorts)\
**Post date:** [November 21, 2022, 2:57pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/1 "2022-11-21T14:57:25Z")

</div>

Hi, I've just started with a prestudy project for a data lineage use case.

Right now I'm using a rather simple graph of Data- and Process-Objects having impact on each other (the graph model consists of a node "Object" with one self-reference "has\_impact\_on").

There are _only 1,548 Object-nodes and 3,352 has\_impact\_on-references_ in the graph (although with some cycles), but my **queries don't terminate** , e.g.:

MATCH p=(n)-[\*]-\>()  
where n.Obj\_MEMBER = 'CT\_MAPPING'  
RETURN p

MATCH p=(n)-[\*]-\>(m)  
where n.Obj\_MEMBER = 'CT\_MAPPING'  
RETURN m.Obj\_TYPE\_CAT, m.Obj\_MEMBER, length(p), [x in nodes(p)|x.Obj\_ID]

Could the cycles be the problem? Are there better alternatives, or is it because I'm currently testing on a free aura instance?

Thanks a lot for your help.

Best regards, Thomas

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [November 21, 2022, 3:42pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/2 "2022-11-21T15:42:09Z")

</div>

[@harmonie\_shorts](https://community.neo4j.com/t5/user/viewprofilepage/user-id/15756)

given the usage of

```auto
where n.Obj_MEMBER = 'CT_MAPPING'

```

this would lend itself to indexing Obj\_MEMBER. But to do so w would need to know the label this property is associated with. And for example if this property `Obj_MEMBER` and if asssociated with a label named 'Label101` then create an index as

```auto
create index :Label101(Obj_Member);

```

``and then also change the query to reference this label and thus

```auto
MATCH p=(n:Label101)-[*]->()
where n.Obj_MEMBER = 'CT_MAPPING'
RETURN p

```

your current cypher is going to walk the entire graph and expand all paths.

---

<div class="post-metadata">

**Author:** ![harmonie\_shorts](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@harmonie\_shorts](https://community.neo4j.com/u/harmonie_shorts)\
**Post date:** [November 22, 2022, 1:10pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/3 "2022-11-22T13:10:12Z")

</div>

PS: it didn't quite work as expected, either my way is still incorrect, or something else is missing:  
This cypher still hasn't terminated after more than 1 hour:

MATCH p=(n:Object)-[\*]-\>(m)

where n.Obj\_MEMBER = 'CT\_MAPPING'

RETURN m.Obj\_TYPE\_CAT, m.Obj\_MEMBER, length(p), [x in nodes(p)|x.Obj\_ID] LIMIT 100000

?

---

<div class="post-metadata">

**Author:** ![harmonie\_shorts](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@harmonie\_shorts](https://community.neo4j.com/u/harmonie_shorts)\
**Post date:** [November 22, 2022, 11:25am UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/4 "2022-11-22T11:25:05Z")

</div>

Thanks a lot, the Nodes' label is "Object", so I've created an Index using this statement:

CREATE INDEX IdxObjectMember  
FOR (n:Object)  
ON (n.Obj\_MEMBER)

, then I slightly modified my query by specifying n, following your recommendation (I hope):

MATCH p=( **n:Object** )-[\*]-\>()  
where n.Obj\_MEMBER = 'CT\_MAPPING'  
RETURN p LIMIT 1000

May I ask another Noob-Question, because I'm a little bit confused:  
As far as I've understood, neo4j uses simple pointer operations for traversing the Graph-Relationships.  
Why should an index on Nodes improve the execution, if - as in my case - a unique starting point for the traversal is provided (here: Object.Object\_MEMBER = 'CT\_MAPPING'?

Thanks a lot for your help and understanding 🙂

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [November 22, 2022, 1:15pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/5 "2022-11-22T13:15:35Z")

</div>

[@harmonie\_shorts](https://community.neo4j.com/t5/user/viewprofilepage/user-id/15756) the original

```auto
MATCH p=(n)-[*]->()
where n.Obj_MEMBER = 'CT_MAPPING'
RETURN p

```

effectively says `match p=(n) .....` i.e. look at every node. If your graph has 100 million nodes but only 20k are with label `:Object` then we look at all 100 million nodes. Whereas a `match p=(n:Object)....` says only look at the 20k nodes with a label of `:Object'.

Further if you create a index on `:Object', and as described in prior posts above, then we use the index to find which nodes have said property/value per index. And since this index is in some b-tree like form if you have 20k `:Object' nodes even traversing to the bottom leaf of the 20k index could take a significantly small number of comparisons (i.e with 1 comparison you can eliminate 10k entries, 2 comparisons you can eliminate an additional 5k, 3 comparisons, another 2.5k etc)

---

<div class="post-metadata">

**Author:** ![harmonie\_shorts](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@harmonie\_shorts](https://community.neo4j.com/u/harmonie_shorts)\
**Post date:** [November 22, 2022, 1:19pm UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/6 "2022-11-22T13:19:32Z")

</div>

hmm... but I've only got 1,550 Object-Nodes and 3,350 relationships?

Here's the simple Graph Model with query and Index, it's been running for 4,5 hours now.  
What's wrong?:

 ![neo4j_lineage_performance_issue.jpg](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/c/c/cc7d4d1eba39e7c216179859fb83dd3dee1fc8c9.jpeg "neo4j\_lineage\_performance\_issue.jpg")

---

<div class="post-metadata">

**Author:** ![harmonie\_shorts](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@harmonie\_shorts](https://community.neo4j.com/u/harmonie_shorts)\
**Post date:** [November 23, 2022, 7:45am UTC](https://community.neo4j.com/t/performance-issues-with-simple-match-on-small-graph-lineage-analysis-cypher-doesnt-terminate/59022/7 "2022-11-23T07:45:54Z")

</div>

Here's an explain query:

 ![neo4j_lineage_performance_issue_explain.jpg](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/4/f/4f785702a519159fbfd759b0fd1e077aab86de5a.jpeg "neo4j\_lineage\_performance\_issue\_explain.jpg")
