# Simple relational query is very slow

**URL:** https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338
**Category:** Neo4j Graph Platform
**Tags:** migrated, cypher-tagged
**Created:** [January 11, 2023, 3:57pm UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338 "2023-01-11T15:57:00Z")
**Posts on this page:** 5
**Page:** 1

<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: [January 11, 2023, 3:57pm UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338/1 "2023-01-11T15:57:00Z")

</div>

I have a simple relational query as below:

```auto
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity) return e,rel,e2

```

And the query plan is as below:

![plan.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/2/4/24384dd9af8defb2b3993188f43b180df5a84532.png "plan.png")

"Mona Lisa" entity has 1100 relations in total - 1050 of them to Property nodes, 50 of them to Entity nodes. What I want is only Entities. My database has about 50M nodes and a few billions of relationships. Considering the logic behind Neo4j, the database size should not be important when querying with a start node. This query takes 20 seconds - I'd expect 1 sec. If that's the case why is this query is slow?

Thanks.

---

<div class="post-metadata">

### Author: ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)
#### Post date: [January 11, 2023, 6:43pm UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338/2 "2023-01-11T18:43:55Z")

</div>

Do you have different relationship types for each of these two node labels? If not, you should considered doing so. You can use the following query, which should be more efficient since the relationships can be filtered by type instead of iterating over every relationship to get the other node and filter on :Entity

match (e:Entity{name:”Mona Lisa”})-[rel:HAS\_ENTITY]-\>(e2) return e, rel, e2

---

<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: [January 11, 2023, 5:28pm UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338/3 "2023-01-11T17:28:14Z")

</div>

[@cuneyttyler](https://community.neo4j.com/t5/user/viewprofilepage/user-id/290)

it probably shouldnt matter as it should just work but

a. what version of Neo4j?

b. are you running this via the Neo4j Browser, which thus has to render/visualize the results, or via bin/cypher-shell?

---

<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: [January 11, 2023, 6:23pm UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338/4 "2023-01-11T18:23:58Z")

</div>

Neo4j Version is 4.7, running via browser - but as you talked about rendering, I realized that I have a very big values for entities for some searching logic so I returned only names of entities and it's fine now. Thanks.

---

<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: [January 12, 2023, 4:15am UTC](https://community.neo4j.com/t/simple-relational-query-is-very-slow/58338/5 "2023-01-12T04:15:44Z")

</div>

I have different relationship types but they are uncountable (semantic web properties, so a very big number of relationships).

The reason the query was slow actually is that I have a very big string property in Entity nodes. Returning those for 1k entities takes too much time so I edited the query to return only 'name' of entities and now query finishes in a reasonable time.

```auto
PROFILE MATCH(e:Entity {name:'Mona Lisa'})-[rel]->(e2:Entity) return e.name,rel,e2.name

```
