Neo4j: Generic/Vague relationship names

Neo4j: Generic/Vague relationship names by Mark Needham.

From the post:

An approach to modelling that I often see while working with Neo4j users is creating very generic relationships (e.g. HAS, CONTAINS, IS) and filtering on a relationship property or on a property/label at the end node.

Intuitively this doesn’t seem to make best use of the graph model as it means that you have to evaluate many relationships and nodes that you’re not interested in whereas if you use a more specific relationship type that isn’t the case.

However, I’ve never actually tested the performance differences between the approaches so I thought I’d try it out.

I created 4 different databases which had one node with 60,000 outgoing relationships – 10,000 which we wanted to retrieve and 50,000 that were irrelevant.

I modelled the ‘relationship’ in 4 different ways…

  • Filter by relationship type
  • Filter by end node label
  • Filter by relationship property
    (node)-[:HAS {type: “address”}]->(address)
  • Filter by end node
    (node)-[:HAS]->(address {type: “address”})

…and then measured how long it took to retrieve the ‘has address’ relationships.

See Mark’s post for the test results but the punch line is the less filtering required, the faster the result.

Designing data structures for eventual queries seems sub-optimal to me.


Comments are closed.