This chapter mainly introduces the different data models. The author gives the data model construction method
Modeling data structures for real-world requirements
The data model when storing data structures
The way the data model is manipulated
What about the hardware level
Relational versus document
The relational model
Data is organized into relationships, which in SQL is the concept of a table, and each relationship is an unordered collection of meta-ancestors (called rows in SQL). The core of relational databases is to commercialize data processing, providing transaction processing and batch processing.
Relational models have object-relational mismatches, such as interacting objects and storing objects (multiple tables) that do not match (a concept described in the book called impedance mismatch). In the case of one-to-many data, the author gives an example of checking a resume, which consists of multiple tables. The association of multiple tables will reduce the query efficiency. However, in many-to-one and many-to-many cases, the relationship between data text information and ID is maintained, which is more suitable for related businesses (many-to-many, for example, nationality and ID are a table, while ID is filled in the information table of personnel).
The document type
The book uses the example of reviewing a resume to introduce several advantages of the document model
- Objects and relationships match. Because the storage structure is JSON, it is ideal for one-to-many scenarios and does not require associated table queries
- Flexible patterns. Relational types require table locks, but document types do not
There are also some disadvantages
- Not applicable to many-to-one, many-to-many scenarios. This is mainly because the document model is not as optimized for join as the relational model
- Limitations of query data. If you access a small part of a document using JSON or XML, the database will load the entire document, resulting in low efficiency
merge
-
Relational databases such as mysql support JSON data storage
-
The client driver automatically resolves the reference relation (Join) of mongoDb and other document databases.
Data query language
Declarative language
Tell the service the input criteria and the desired results. This way the implementation details are hidden and the user does not need to care about how it is implemented internally. At the same time, how operations are scheduled by services is also more suitable for parallel processing. Examples include SQL and CSS in Web development.
Database languages are better suited to declarative languages.
Imperative language
Tell the service how to do it. This approach requires the user to write the steps. Not very suitable for parallel processing.
MapReduce
An example is given to illustrate the use of declarative languages (defining types) and imperative languages (executing steps) in map and Reduce steps.
Graph data model
When the data association in many-to-many relationships is very complex, such as in social networks, the relational model cannot do the job.
The graph data model includes vertices and edges.
Attribute graph model
The vertices
- Unique identifier
- The edge collection
- The edge collection
- Attribute set
edge
- Unique identifier
- The vertex where the edge begins
- The vertex where an edge ends
- Labels for relationships between vertices
- Attribute set
Cypher query language is a query language for attribute graph models
Ternary memory model
Adopt subject-predicate-object.
The vertices
- The main body
- Objects can also be vertices
edge
- The predicate
- The key-value pairs of the predicate and the object gastrointestinal body
SPARQL and Datalog are the model query languages
other
This chapter mainly covers some data models. Application of different data models in different scenarios.