Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday, 21 February 2024

Index-Free Adjacency in Graph Database

Index-free adjacency is a core concept in graph databases, enabling efficient traversal of relationships between nodes without the need for indexing. Here's an example demonstrating index-free adjacency using Neo4j and its Cypher query language:


Consider a simple social network graph where users are connected by "FRIEND" relationships:


// Create nodes representing users

CREATE (alice:Person {name: 'Alice'})

CREATE (bob:Person {name: 'Bob'})

CREATE (carol:Person {name: 'Carol'})


// Create relationships representing friendships

CREATE (alice)-[:FRIEND]->(bob)

CREATE (bob)-[:FRIEND]->(carol)


In this example:


- We create three nodes representing users: Alice, Bob, and Carol.

- We establish FRIEND relationships between them, representing friendships in the social network.


Now, let's traverse these relationships using index-free adjacency:


// Find all friends of Alice

MATCH (alice:Person {name: 'Alice'})-[:FRIEND]->(friend)

RETURN friend.name AS Friend


In this Cypher query:

- We start with the node representing Alice ((alice:Person {name: 'Alice'})).

- We traverse outgoing FRIEND relationships from Alice to her friends.

- We return the names of Alice's friends.


The traversal of FRIEND relationships occurs using index-free adjacency. Neo4j internally uses pointers or references between nodes to efficiently follow the relationships without the need for indexing.


This example illustrates how index-free adjacency enables efficient traversal of relationships in graph databases, contributing to their high performance and scalability in handling interconnected data.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.