?
- 有哪些 data model? 它们之间的区别和联系是什么? 各自解决了什么场景下的问题? 如何融合?
- 每个 data model 对应的 query language 是什么? 有什么特点?
- 关系型和文档型之间的差异是什么?
- 什么是 nosql? data model 和 query language 的历史发展?
- it’s just a question of whether the schema is explicit (enforced on write) or implicit (handled on read)?
- 关系型数据库的限制?什么导致了这些限制?如何打破这些限制?
Overview
许多应用都由分层的 data-model 组成,上层屏蔽下层的复杂性,data-model 决定我们解决问题的思维模式.本节介绍 relational model, document model, graph-based model
3 种 data-model 和其对应的 query language。
Relational model 解决数据之间 many-to-many
关系的问题,但是无法适应所有应用场景,于是 NoSQL datastore
应运而生,主要分为 2 大类:
-
Doucument database
: Document databases target use cases where data comes in self-contained documents and relationships between one document and another are rare. -
Graph databases
: Graph databases go in the opposite direction, targeting use cases where anything is potentially related to everything.
适应于一个 data-model 的数据也可以用其他的 data-model 来组织,比如: graph data can be represented in a relational database。用不合适的 data-model 来组织数据会使得数据变得难以使用, That’s why we have different systems for different purposes, not a single one-size-fits-all solution.
定义数据存储格式 -> 在其上定义查询语言.
Relational Model Versus Document Model
Relational Model
Relational Model 由 row(tuple) 组成 table(relation),主要的 use case 是 transaction processing
和 batch processing
。其屏蔽了底层存储的实现细节,对外提供 sql 这种声明式的 query language.
Object-oriented 和 relational model 之间存在差异,需要 orm(mybatis 等), 但是也无法完全屏蔽这种差异.
A key insight of the relational model was this: you only need to build a query optimizer once, and then all applications that use the database can benefit from it
Document Model
适用于数据之间 one-to-many 的关系,对 join 支持比较弱.
NoSql(Not Only SQL) 产生驱动因素:
- A need for greater scalability than relational databases can easily achieve, includ‐ing very large datasets or very high write through