现实中不少数据都是用图来表达的,好比社交网络中人与人的关系、地图数据、或是基因信息等等。RDBMS并不适合表达这类数据,并且因为海量数据的存在,让其显得捉襟见肘。NoSQL数据库的兴起,很好地解决了海量数据的存放问题,图数据库也是NoSQL的一个分支,相比于NoSQL中的其余分支,它很适合用来原生表达图结构的数据。html
下面一张图说明,相比于其余NoSQL,图数据库存放的数据规模有所降低,可是更可以表达复杂的数据。node
一般来讲,一个图数据库存储的结构就如同数据结构中的图,由顶点和边组成。程序员
Neo4j是图数据库中一个主要表明,其开源,且用Java实现。通过几年的发展,已经能够用于生产环境。其有两种运行方式,一种是服务的方式,对外提供REST接口;另一种是嵌入式模式,数据以文件的形式存放在本地,能够直接对本地文件进行操做。sql
Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中。Neo4j也能够被看做是一个高性能的图引擎,该引擎具备成熟数据库的全部特性。程序员工做在一个面向对象的、灵活的网络结构下而不是严格、静态的表中——可是他们能够享受到具有彻底的事务特性、企业级的数据库的全部好处。数据库
Neo4j因其嵌入式、高性能、轻量级等优点,愈来愈受到关注。网络
在一个图中包含两种基本的数据类型:Nodes(节点) 和 Relationships(关系)。Nodes 和 Relationships 包含key/value形式的属性。Nodes经过Relationships所定义的关系相连起来,造成关系型网络结构。数据结构
从这几个方面来讲,Neo4j是一个合适的选择。Neo4j……nosql
做为一个图形NoSQL数据库,Neo4j提供了大量的功能,但没有什么解决方案是完美的。在如下这些用例中,Neo4j就不是很是适合的选择:分布式
The node records contain only a pointer to their first property and their first relationship (in what is oftentermed the _relationship chain). From here, we can follow the (doubly) linked-list of relationships until we find the one we’re interested in, the LIKES relationship from Node 1 to Node 2 in this case. Once we’ve found the relationship record of interest, we can simply read its properties if there are any via the same singly-linked list structure as node properties, or we can examine the node records that it relates via its start node and end node IDs. These IDs, multiplied by the node record size, of course give the immediate offset of both nodes in the node store file.oop
上面的英文摘自<Graph Databases>
(做者:IanRobinson) 一书,描述了 neo4j 的存储模型。Node和Relationship 的 Property 是用一个 Key-Value 的双向列表来保存的; Node 的 Relatsionship 是用一个双向列表来保存的,经过关系,能够方便的找到关系的 from-to Node. Node 节点保存第1个属性和第1个关系ID。
经过上述存储模型,从一个Node-A开始,能够方便的遍历以该Node-A为起点的图。下面给个示例,来帮助理解上面的存储模型,存储文件的具体格式在第2章详细描述。
在这个例子中,A~E表示Node 的编号,R1~R7 表示 Relationship
编号,P1~P10 表示Property
的编号。
Node
保存了第1个Property
和 第1个Relationship
:http://www.cnblogs.com/ljhero/archive/2012/05/13/2498039.html
底层原理:http://sunxiang0918.cn/2015/06/27/neo4j-%E5%BA%95%E5%B1%82%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84%E5%88%86%E6%9E%90/