Because you're asking for EVERY possible path. It's an N^n problem.

Consider:

```
CREATE (a:Node {name:"A"})-[:REL]->(b:Node {name:"B"})-[:REL]->(c:Node {name:"C"}), (c)-[:REL]->(a);
MATCH p=()-[*]-() RETURN p; # 18 possible paths
```

Now, one more node, two more rels...

```
CREATE (a:Exponential {name:"A"})-[:REL]->(b:Exponential {name:"B"})-[:REL]->(c:Exponential {name:"C"})-[:REL]->(d:Exponential {name:"D"}), (d)-[:REL]->(a), (a)-[:REL]->(c);
MATCH p=(:Exponential)-[*]-(:Exponential) RETURN p # 86 results, 12 of them 5 hops long.
```

console.neo4j.org

You should write your query to ensure it returns all nodes and paths, with the least number of result rows, or at least minimizing duplicates in the results.

The tie-fighter `)-[*]-(`

gives you *every possible path, any number of hops*, so with large graphs it blows-up quickly. What do you want to do with the result? Just see it in the browser, or do you want to do work?

An additional note, is that if you *can* specify the relationship name, *do*, it will make the query faster.

```
MATCH (:Project {name:"Project1"}) -->(s:Submission)-->(t:TypeDeclaration)
WITH t
MATCH (t)-[1..11]-(x:TGraph)
WITH t, x
MATCH (t)-[tRx]-(x), (x)-[xRx]-(x)
RETURN t, x, tRx, xRx
```

## How to design a graph for efficient queries

- You should write your query to ensure it returns all nodes and paths, with the least number of result rows, or at least minimizing duplicates in the results.
- You want the whole graph of all nodes below a
`:TypeDeclaration`

node.

Note: Wherever you can rely on directionality *do*, it's the first method of reducing results.

Since what you're trying to do is "find all the nodes beneath a `:TypeDeclaration`

, and all the relationships between those nodes... build your graph to make the first part of that *one hop*.

```
MATCH (:Project {name:"Project1"}) -->(s:Submission)-->(t:TypeDeclaration)
WITH t
MATCH (t)-[r]-(:TGraph)
SET r :DECLARATION; # preserve original hierarchy for later
MATCH (:Project {name:"Project1"}) -->(s:Submission)-->(t:TypeDeclaration)
WITH t
MATCH (t)-[1..11]-(x:TGraph)
WITH t, x
CREATE (t)<-[:CLASS]-(x);
```

*Now* your queries can be *fast*

```
MATCH (:Project {name:"Project1"}) -->(s:Submission)-->(t:TypeDeclaration)<-[:CLASS]-(x:TGraph)
WITH x
MATCH (x)-[r]-(x)
RETURN x, r
```

... and if you still *really* want all paths, you can do that... but with 200 nodes you're likely looking at millions of paths...

```
MATCH (:Project {name:"Project1"}) -->(s:Submission)-->(t:TypeDeclaration)<-[:CLASS]-(x:TGraph)
WITH t, x
MATCH p=(t)-[:DECLARATION]-(x)-[*]-(x)
RETURN p
```