https://github.com/famousdraw

Neo4j Fundamentals-Native Graph Advantage

VIDEO

Native Graph Advantage

VideoTranscript
 

Neo4j is a native graph database

Neo4j is a native graph database, meaning that everything from the storage of the data to the query language have been designed specifically with traversal in mind.

Where native graph databases stand apart from other databases is the concept of index-free adjacency. When a database transaction is committed, a reference to the relationship is stored with the nodes at both the start and end of the relationship. As each node is aware of every incoming and outgoing relationship connected to it, the underlying graph engine will simply chase pointers in memory - something that computers are exceptionally good at.

Index-free adjacency (IFA)

One of the key features that makes Neo4j graph databases different from an RDBMS is that Neo4j implements index-free adjacency.

RDBMS query

RelationalTable1

To better understand the benefit of index-free adjacency, let’s look at how a query executes in an RDBMS.

Suppose you have this table in the RDBMS.

You execute this SQL query to find the third-degree parents of the group with the ID of 3:

SQL
 
SELECT PARENT_ID
FROM GROUPS
WHERE ID = (SELECT PARENT_ID
    FROM GROUPS
    WHERE ID = (SELECT PARENT_ID
        FROM GROUPS
        WHERE ID = 3))

The result of this query is 1, but in order to determine this result, the SQL Server needed to:

  1. Locate the innermost clause.

  2. Build the query plan for the subclause.

  3. Execute the query plan for the subclause.

  4. Locate the next innermost clause.

  5. Repeat Steps 2-4.

Resulting in:

  • 3 planning cycles

  • 3 index lookups

  • 3 DB reads

Neo4j storage

With index-free adjacency, Neo4j stores nodes and relationships as objects that are linked to each other via pointers. Conceptually, the graph looks like:

IFA-1-new

These nodes and relationships are stored as:

IFA-2-new

Neo4j Cypher query

Suppose we had this query in Cypher:

Cypher
 
MATCH (n) <-- (:Group) <-- (:Group) <-- (:Group {id: 3})
RETURN n.id

Using IFA, the Neo4j graph engine starts with the anchor of the query which is the Group node with the id of 3. Then it uses the links stored in the relationship and node objects to traverse the graph pattern.

IFA-3-new

To perform this query, the Neo4j graph engine needed to:

  1. Plan the query based upon the anchor specified.

  2. Use an index to retrieve the anchor node.

  3. Follow pointers to retrieve the desired result node.

The benefits of IFA compared to relational DBMS access are:

  • Fewer index lookups.

  • No table scans.

  • Reduced duplication of data.

Check your understanding

1. Index-free adjacency

What are the key benefits of Neo4j’s index-free adjacency?

  • Foreign keys are built into each node.

  • Fewer index lookups.

  • No table scans.

  • Reduced duplication of data.

posted on 2022-05-04 12:36  红色MINI  阅读(57)  评论(0编辑  收藏  举报

导航