Database Reference
In-Depth Information
define relationships between nodes via edges, and that's why it is easy to understand
them in terms of RDBMS concepts. Building graph-like queries with an RDBMS is
certainly possible but as discussed previously it will be of very limited use. With non-
graph databases, the ability to run graph-based queries for traversal or building graph
structures is not supported and could be cumbersome to build. Because of inherent
graph data structure support, graph databases will have an edge over traditional
RDBMS.
A few differences between RDBMS and graph databases are
There is no need for index lookup with graph databases, as nodes or ver-
tices are aware of properties they are connected with (e.g., edges)
whereas with RDBMS we need to rely on an indexing mechanism.
Two vertices interconnected via edges can be different in properties and
may evolve dynamically, but RDBMS imposes a fixed set of schema.
With graph databases, the relationship between two vertices is stored at
the record level whereas with RDBMS it is defined at the table level.
One thing we need to keep in mind is that the current era of application develop-
ment is one of using specific technologies for specific needs , which is a good fit for
building polyglot or hybrid solutions. This means that for cases in which your needs
are best served by running graph-like queries and your requirements lend themselves to
a faster graph-based model, then the answer is simple: Use graph databases. A graph
database uses nodes and edges and their properties to build and store data in a graph
structure. Every element in a graph databases has a reference to adjoining nodes, which
means no index lookup will be required. Figure 7-4 shows an example of a graph data-
base storing Twitter users as nodes and their followers as edges. Each node contains an
fname, id, lname, and role as properties, whereas each edge has a property to denote
the date when a user became a follower of the adjoining node (i.e., user).
Figure 7-5 shows a Twitter connection and follower graph for users mevivs,
chris_n, apress_team, and melissa_m. Here the vertex apress_team is being followed
by the mevivs and melissa_m vertices. On the other hand, a transitive relation/traversal
exists between chris_n, who is following mevivs, who follows apress_team, and the
apress_team follows chris_n. In the “Gremlin Shell” and “Use Cases” sections, we will
refer to the same Twitter example to explore command-line tools and Java APIs in
sample exercises. When considering such transitive graph queries, one thing worth dis-
cussing is that the ways graph databases handle such queries is different than SQL
queries. Handling of such transitive queries with SQL is not straightforward and would
require performing complex joins, unions, or intersections. But handling such transitive
 
Search WWH ::




Custom Search