Search code examples
neo4jgraph-databasesdatamodel

"graph databases store relationship data as first-class entities", what does it mean exactly?


I want to know what does this sentence mean exactly in graph databases?

"graph databases store relationship data as first-class entities"

can you please give an example?


Solution

  • In the relational database world, relationships between rows are not physically stored in the hard disk. Instead, foreign keys are used to reference a row from another row. Foreign keys works like pointers. This way, relationships between rows are calculated at query time using JOIN-like operators. This type of operations has an expensive cost and this cost grows exponentially according the table size.

    On the other hand, when dealing with graph databases like Neo4j, the relationships between your nodes are physically stored in the hard disk. Each stored relationships points to a start and an end node. This way the database engine can walk over the graph following these relationships, without the needing of JOIN operations. This is why you can say that relationships are "first-class entities in graph databases".