neo4j Database Simple

Source: Internet
Author: User
Tags neo4j

As the world's Advanced map database, NEO4J today, the company has become the first choice for many internet. Neo4j It is based on Java open Source map database development, another NoSQL database. NEO4J is at the same time guaranteeing a good portrayal of the data relationship. The ACID properties of traditional relational data are also supported. It also has a good performance in terms of storage efficiency, cluster support, and fail-over redundancy. Recently due to the relationship of laboratory projects. Have a certain understanding of the neo4j.

At the same time. I also have a lot of interest in their design ideas and architecture, so write down this blog to help you better understand the database, but also share a bit of understanding.

Design concept

NEO4J's design motive is to better describe the relationship between narrative entities at the same time and more efficiently. In real life, each entity is inextricably linked to other entities around it, and the information stored in these relationships is even larger than the properties of the body itself. Then the traditional relational database is more focused on characterizing the attributes inside the entity. The relationship between entities and entities is usually implemented using foreign keys. Therefore, the join operation is usually required to solve the relationship. Join operations are often time-consuming. The explosive growth of the Internet, especially mobile Internet, has already overwhelmed the traditional relational database, and with the high demand for relationships such as social networking, it is no advantage to say relational databases. The graph database, as a database that focuses on the relationship between narrative data, emerges as a very important part of NoSQL. And Neo4j is one of the best in the graph database.

The NEO4J database has only two types of data:

    • Node nodes: Nodes are similar to Entities (entity) of the E-r graph. Each entity can have 0 to many properties, which exist in the form of a key-value pair. And there are no category requirements for attributes. There is no need for pre-defined. Other than that. Also agreed to label each node. Different types of nodes to differ.
    • Relationship relationship: The relationship is similar to the E-r diagram (relationship). A relationship has a starting node and a terminating node component. In addition, like node. Relationships can also have multiple properties already tagged

Its detailed structure for example is as follows: and an actual graph database sample is like this as seen:

It is based on this design concept. NEO4J has the following features:

    • Relationships are implemented when they are created. Thus it is an O (1) operation when querying the relationship
    • All relationships are equally important in the neo4j.
    • The algorithm provides depth-first search, breadth-first search, shortest path, simple path already dijkstra and so on.
Storage structure of NEO4J

Now let's look at how data is stored in neo4j. The first is the format of node nodes: The Node:in_use(byte)+next_rel_id(int)+next_prop_id(int) detailed meanings of each bit are as follows:

    • In_use:1 indicates that the node is in use and 0 means it is deleted
    • next_rel_id (int): The node's next relationship ID
    • next_prop_id (int): The ID of the next property of the node

Relation format:in_use+first_node+second_node+rel_type+first_prev_rel_id+first_next_rel_id+second_prev_rel_id+second_next_rel_id+next_prop_id

    • IN_USE,NEXT_PROP_ID: Ibid.
    • First_node: The starting node of the current relationship
    • Second_node: The terminating node of the current relationship
    • Rel_type: Relationship Type
    • FIRST_PREV_REL_ID & first_next_rel_id: The first and last relationship ID of the starting node
    • SECOND_PREV_REL_ID & second_next_rel_id: Terminating the first and last relationship ID of a node

I believe that after I have seen the structure of the deposit. You know why neo4j is so fast when it comes to querying node relationships. Because each node has a relationship that is directly within the defined domain of that node. A direct interview is available. There is no need to find another table.

Here's a sample of the traversal of a graph:

    • relationship 1:01 00000001 00000003  000000 00   00000002 00000000   00000003 ffffffff    ffffffff node1, node 3,node3 has other relationships. So put the node3 in the queue. Same time interview relationship 0
    • relationship 0:01 00000001 00000002  00000000   00000001 ffffffff    ffffffff ffffffff    ffffffff node1 Node2, visit to complete the node1 of all relations. Exit Node3
    • The final result such as the following:
(1)–[KNOWS,2]–>(4)(1)–[KNOWS,1]–>(3)(1)–[KNOWS,0]–>(2)(1)–[KNOWS,1]–>(3)–[KNOWS,5]–>(7)(1)–[KNOWS,1]–>(3)–[KNOWS,4]–>(6)(1)–[KNOWS,1]–>(3)–[KNOWS,3]–>(5)
The difference between neo4j and relational database

In fact, through the above explanation, I believe we all have a certain understanding of the differences between NEO4J and RDBMS (relational Database Management System). Now use the following form to clean up again:

Neo4j Rdbms
Agree on simple and diverse management of data Highly structured data
Flexible data entry and definition. Not limited by data type and number, no predefined The table schema needs to be defined in advance. Changes and additions to data structures and types are complex and strictly limited
Relational query operation for constant time Time-consuming relational query operations
Propose a new query Language cypher, query statements more simple Query statements are more complex, especially when joins or union operations are involved

Finally, the following two images show the difference between the two in the query relationship: rdbmsneo4j

About neo4j detailed installation and use, not the focus of the article, if you want to really get started with neo4j, can go to neo4j official website has a lot of information


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

neo4j Database Simple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.