HanXu
HanXu

Reputation: 5597

Neo4j why picking a single node and a single edge take so long?

I am trying to test the speed of Neo4j, thus I created an empty database and then populate it with 10,000 users.

Now I run the following query

MATCH (n) RETURN id(n) LIMIT 1;

Surprisingly, it takes 1069 ms!

Then I run the following query (note: I haven't created any edges)

MATCH ()-[r]-() RETURN id(r) LIMIT 1;

which takes 1153ms!

Then I run

MATCH (n) RETURN id(n) SKIP 9900 LIMIT 100

which takes 10427ms.

Is it normal? I think those operations, at least the last one, is quite frequent in an app. I am using a Macbook Air with 1.7GHz Core i5

Upvotes: 0

Views: 55

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

What version of Neo4j are you using?

How do you measure? The Neo4j browser measures multiple roundtrips for additional data.

Also is that the first or a subsequent query?

None of those queries should be that slow. Perhaps you can share your Neo4j configuration?

  1. that one should be really fast
  2. this one goes over all the nodes (or even over the cross product) in your graph and tries to find a relationship at the end it doesn't find any
  3. that one should also be really fat.

Regarding your comment, if you know the first node, your search will be anchored and you don't have to scan all rels in the database.

MATCH (:User {name:"Han"})-[:FRIEND]->(friend)
RETURN friend

Upvotes: 2

Related Questions