2
votes

I'm toying around with Neo4J. My Data consists of users who own objects which are tagged by tags. There my schema looks like:

(:User)-[:OWNS]->(:Object)-[:TAGGED_AS]->(:Tag)

I have written a script that generates me a sample Graph. Currently I have 100 User, ~2500 Tag and ~10k Object nodes in the database. Between those I have ~700k relationships. I know want to find every Object that is not owned by a certain User but related over a Tag the User has used himself. There query looks like:

MATCH (user:User {username: 'Cristal'})
WITH user
MATCH (user)-[:OWNS]->(obj:Object)-[:TAGGED_AS]->(tag:Tag)<-[:TAGGED_AS]-(other:Object)
WHERE NOT (user)-[:OWNS]->(other)
RETURN other
LIMIT 20

However, this query runs ~1-5 minutes (depending on the user and how many objects he owns), which is a not only a bit to slow. What am I doing wrong? I consider this a rather "trivial" query against a graph of modest size. I'm using Neo4J 2.1.6 Community and already set the Java Heap to 2000 MB (and I can see that there is a Java process using this much). Am I missing an index or something like that (I'm new to Neo4J)?

I honestly expected the result to be pretty much instant especially considering that the Neo4J docs mention the I should use a heap between 1 and 4 GB for 100 million objects...and I'm only close to a 1/100 of this number.

If it is my Query (which I hope and expect) how can I improve it? What is something you have to be aware when writing queries?

1

1 Answers

0
votes

Do you have an index on the username property?

CREATE INDEX ON :User(username)

Also you don't really need that WITH there, so maybe drop it to see if it helps:

MATCH (user:User {username: 'Cristal'})-[:OWNS]->(obj:Object)-[:TAGGED_AS]->(tag:Tag)<-[:TAGGED_AS]-(other:Object)
WHERE NOT (user)-[:OWNS]->(other)
RETURN other
LIMIT 20

Also, I don't think it will make a different, but you can drop the obj and tag variables since you're not using them elsewhere in the query.

Also, if you're generating sample graphs you may want to check out GraphGen:

http://graphgen.neoxygen.io/