Database Reference
In-Depth Information
computing power to calculate. Then you discard more than 99% to return the just under
1,000 records that you're interested in!
As you can see, relational databases are not so great for modeling many-to-many relation-
ships, especially in large data sets. Neo4j, on the other hand, excels at many-to-many rela-
tionships, so let's take a look at how it performs with the same data set. Instead of tables,
columns, and foreign keys, you're going to model users as nodes, and friendships as rela-
tionships between nodes.
1.3. Graph data in Neo4j
Neo4j stores data as vertices and edges, or, in Neo4j terminology, nodes and relationships .
Users will be represented as nodes, and friendships will be represented as relationships
between user nodes. If you take another look at the social network in figure 1.1 , you'll see
that it represents nothing more than a graph, with users as nodes and friendship arrows as
relationships.
There's one key difference between relational and Neo4j databases, which you'll come
across right away: data querying. There are no tables and columns in Neo4j, nor are there
any SQL-based select and join commands. So how do you query a graph database?
The answer is not “write a distributed MapReduce function.” Neo4j, like all graph data-
bases, takes a powerful mathematical concept from graph theory and uses it as a powerful
and efficient engine for querying data. This concept is graph traversal , and it's one of the
main tools that makes Neo4j so powerful for dealing with large-scale graph data.
1.3.1. Traversing the graph
The traversal is the operation of visiting a set of nodes in the graph by moving between
nodes connected with relationships. It's a fundamental operation for data retrieval in a
graph, and as such, it's unique to the graph model. The key concept of traversals is that
they'relocalized—queryingthedatausingatraversalonlytakesintoaccountthedatathat's
required, without needing to perform expensive grouping operations on the entire data set,
like you do with join operations on relational data.
Search WWH ::




Custom Search