Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed May 18, 2019
1 parent b78a587 commit 7fa7833
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 56 deletions.
51 changes: 23 additions & 28 deletions docs/notes/数据库系统原理.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

在选择封锁粒度时,需要在锁开销和并发程度之间做一个权衡。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/1a851e90-0d5c-4d4f-ac54-34c20ecfb903.jpg" width="300"/> </div><br>

## 封锁类型

Expand All @@ -148,8 +147,8 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

| - | X | S |
| :--: | :--: | :--: |
|X|×|×|
|S|×||
| **X** |×|×|
| **S** |×||

### 2. 意向锁

Expand All @@ -168,10 +167,10 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

| - | X | IX | S | IS |
| :--: | :--: | :--: | :--: | :--: |
|X |× |× |× | ×|
|IX |× ||× ||
|S |× |× |||
|IS |× ||||
| **X** |× |× |× | ×|
| **IX** |× ||× ||
| **S** |× |× |||
| **IS** |× ||||

解释如下:

Expand Down Expand Up @@ -292,14 +291,16 @@ SELECT ... FOR UPDATE;

强制事务串行执行。

需要加锁实现,而其它隔离级别通常不需要。

----

| 隔离级别 | 脏读 | 不可重复读 | 幻影读 | 加锁读 |
| :---: | :---: | :---:| :---: | :---: |
| 未提交读 |||| × |
| 提交读 | × ||| × |
| 可重复读 | × | × || × |
| 可串行化 | × | × | × ||
| 隔离级别 | 脏读 | 不可重复读 | 幻影读 |
| :---: | :---: | :---:| :---: |
| 未提交读 ||||
| 提交读 | × |||
| 可重复读 | × | × ||
| 可串行化 | × | × | × |

# 五、多版本并发控制

Expand Down Expand Up @@ -327,7 +328,7 @@ MVCC 使用到的快照存储在 Undo 日志中,该日志通过回滚指针把

以下实现过程针对可重复读隔离级别。

当开始新一个事务时,该事务的版本号肯定会大于当前所有数据行快照的创建版本号,理解这一点很关键。
当开始一个事务时,该事务的版本号肯定大于当前所有数据行快照的创建版本号,理解这一点很关键。数据行快照的创建版本号是创建数据行快照时的系统版本号,系统版本号随着创建事务而递增,因此新创建一个事务时,这个事务的系统版本号比之前的系统版本号都大,也就是比所有数据行快照的创建版本号都大

### 1. SELECT

Expand Down Expand Up @@ -373,7 +374,7 @@ delete;

Next-Key Locks 是 MySQL 的 InnoDB 存储引擎的一种锁实现。

MVCC 不能解决幻读的问题,Next-Key Locks 就是为了解决这个问题而存在的。在可重复读(REPEATABLE READ)隔离级别下,使用 MVCC + Next-Key Locks 可以解决幻读问题。
MVCC 不能解决幻影读问题,Next-Key Locks 就是为了解决这个问题而存在的。在可重复读(REPEATABLE READ)隔离级别下,使用 MVCC + Next-Key Locks 可以解决幻读问题。

## Record Locks

Expand All @@ -394,11 +395,11 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;
它是 Record Locks 和 Gap Locks 的结合,不仅锁定一个记录上的索引,也锁定索引之间的间隙。例如一个索引包含以下值:10, 11, 13, and 20,那么就需要锁定以下区间:

```sql
(negative infinity, 10]
(-, 10]
(10, 11]
(11, 13]
(13, 20]
(20, positive infinity)
(20, +)
```

# 七、关系数据库设计理论
Expand All @@ -415,7 +416,7 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;

## 异常

以下的学生课程关系的函数依赖为 Sno, Cname -> Sname, Sdept, Mname, Grade,键码为 {Sno, Cname}。也就是说,确定学生和课程之后,就能确定其它信息。
以下的学生课程关系的函数依赖为 {Sno, Cname} -> {Sname, Sdept, Mname, Grade},键码为 {Sno, Cname}。也就是说,确定学生和课程之后,就能确定其它信息。

| Sno | Sname | Sdept | Mname | Cname | Grade |
| :---: | :---: | :---: | :---: | :---: |:---:|
Expand All @@ -437,8 +438,6 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;

高级别范式的依赖于低级别的范式,1NF 是最低级别的范式。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/c2d343f7-604c-4856-9a3c-c71d6f67fecc.png" width="300"/> </div><br>

### 1. 第一范式 (1NF)

属性不可分。
Expand Down Expand Up @@ -537,31 +536,27 @@ Entity-Relationship,有三个组成部分:实体、属性、联系。

下图的 Course 和 Student 是一对多的关系。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/292b4a35-4507-4256-84ff-c218f108ee31.jpg" width=""/> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/1d28ad05-39e5-49a2-a6a1-a6f496adba6a.png" width="380px"/> </div><br>

## 表示出现多次的关系

一个实体在联系出现几次,就要用几条线连接。

下图表示一个课程的先修关系,先修关系出现两个 Course 实体,第一个是先修课程,后一个是后修课程,因此需要用两条线来表示这种关系。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/8b798007-e0fb-420c-b981-ead215692417.jpg" width=""/> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/ac929ea3-daca-40ec-9e95-4b2fa6678243.png" width="250px"/> </div><br>

## 联系的多向性

虽然老师可以开设多门课,并且可以教授多名学生,但是对于特定的学生和课程,只有一个老师教授,这就构成了一个三元联系。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/423f2a40-bee1-488e-b460-8e76c48ee560.png" width=""/> </div><br>

一般只使用二元联系,可以把多元联系转换为二元联系。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/de9b9ea0-1327-4865-93e5-6f805c48bc9e.png" width=""/> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/5bb1b38a-527e-4802-a385-267dadbd30ba.png" width="350px"/> </div><br>

## 表示子类

用一个三角形和两条线来连接类和子类,与子类有关的属性和联系都连到子类上,而与父类和子类都有关的连到父类上。

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/7ec9d619-fa60-4a2b-95aa-bf1a62aad408.jpg" width=""/> </div><br>
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/14389ea4-8d96-4e96-9f76-564ca3324c1e.png" width="450px"/> </div><br>

# 参考资料

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 23 additions & 28 deletions notes/数据库系统原理.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

在选择封锁粒度时,需要在锁开销和并发程度之间做一个权衡。

<div align="center"> <img src="pics/1a851e90-0d5c-4d4f-ac54-34c20ecfb903.jpg" width="300"/> </div><br>

## 封锁类型

Expand All @@ -148,8 +147,8 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

| - | X | S |
| :--: | :--: | :--: |
|X|×|×|
|S|×||
| **X** |×|×|
| **S** |×||

### 2. 意向锁

Expand All @@ -168,10 +167,10 @@ MySQL 中提供了两种封锁粒度:行级锁以及表级锁。

| - | X | IX | S | IS |
| :--: | :--: | :--: | :--: | :--: |
|X |× |× |× | ×|
|IX |× ||× ||
|S |× |× |||
|IS |× ||||
| **X** |× |× |× | ×|
| **IX** |× ||× ||
| **S** |× |× |||
| **IS** |× ||||

解释如下:

Expand Down Expand Up @@ -292,14 +291,16 @@ SELECT ... FOR UPDATE;

强制事务串行执行。

需要加锁实现,而其它隔离级别通常不需要。

----

| 隔离级别 | 脏读 | 不可重复读 | 幻影读 | 加锁读 |
| :---: | :---: | :---:| :---: | :---: |
| 未提交读 |||| × |
| 提交读 | × ||| × |
| 可重复读 | × | × || × |
| 可串行化 | × | × | × ||
| 隔离级别 | 脏读 | 不可重复读 | 幻影读 |
| :---: | :---: | :---:| :---: |
| 未提交读 ||||
| 提交读 | × |||
| 可重复读 | × | × ||
| 可串行化 | × | × | × |

# 五、多版本并发控制

Expand Down Expand Up @@ -327,7 +328,7 @@ MVCC 使用到的快照存储在 Undo 日志中,该日志通过回滚指针把

以下实现过程针对可重复读隔离级别。

当开始新一个事务时,该事务的版本号肯定会大于当前所有数据行快照的创建版本号,理解这一点很关键。
当开始一个事务时,该事务的版本号肯定大于当前所有数据行快照的创建版本号,理解这一点很关键。数据行快照的创建版本号是创建数据行快照时的系统版本号,系统版本号随着创建事务而递增,因此新创建一个事务时,这个事务的系统版本号比之前的系统版本号都大,也就是比所有数据行快照的创建版本号都大

### 1. SELECT

Expand Down Expand Up @@ -373,7 +374,7 @@ delete;

Next-Key Locks 是 MySQL 的 InnoDB 存储引擎的一种锁实现。

MVCC 不能解决幻读的问题,Next-Key Locks 就是为了解决这个问题而存在的。在可重复读(REPEATABLE READ)隔离级别下,使用 MVCC + Next-Key Locks 可以解决幻读问题。
MVCC 不能解决幻影读问题,Next-Key Locks 就是为了解决这个问题而存在的。在可重复读(REPEATABLE READ)隔离级别下,使用 MVCC + Next-Key Locks 可以解决幻读问题。

## Record Locks

Expand All @@ -394,11 +395,11 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;
它是 Record Locks 和 Gap Locks 的结合,不仅锁定一个记录上的索引,也锁定索引之间的间隙。例如一个索引包含以下值:10, 11, 13, and 20,那么就需要锁定以下区间:

```sql
(negative infinity, 10]
(-, 10]
(10, 11]
(11, 13]
(13, 20]
(20, positive infinity)
(20, +)
```

# 七、关系数据库设计理论
Expand All @@ -415,7 +416,7 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;

## 异常

以下的学生课程关系的函数依赖为 Sno, Cname -> Sname, Sdept, Mname, Grade,键码为 {Sno, Cname}。也就是说,确定学生和课程之后,就能确定其它信息。
以下的学生课程关系的函数依赖为 {Sno, Cname} -> {Sname, Sdept, Mname, Grade},键码为 {Sno, Cname}。也就是说,确定学生和课程之后,就能确定其它信息。

| Sno | Sname | Sdept | Mname | Cname | Grade |
| :---: | :---: | :---: | :---: | :---: |:---:|
Expand All @@ -437,8 +438,6 @@ SELECT c FROM t WHERE c BETWEEN 10 and 20 FOR UPDATE;

高级别范式的依赖于低级别的范式,1NF 是最低级别的范式。

<div align="center"> <img src="pics/c2d343f7-604c-4856-9a3c-c71d6f67fecc.png" width="300"/> </div><br>

### 1. 第一范式 (1NF)

属性不可分。
Expand Down Expand Up @@ -537,31 +536,27 @@ Entity-Relationship,有三个组成部分:实体、属性、联系。

下图的 Course 和 Student 是一对多的关系。

<div align="center"> <img src="pics/292b4a35-4507-4256-84ff-c218f108ee31.jpg" width=""/> </div><br>
<div align="center"> <img src="pics/1d28ad05-39e5-49a2-a6a1-a6f496adba6a.png" width="380px"/> </div><br>

## 表示出现多次的关系

一个实体在联系出现几次,就要用几条线连接。

下图表示一个课程的先修关系,先修关系出现两个 Course 实体,第一个是先修课程,后一个是后修课程,因此需要用两条线来表示这种关系。

<div align="center"> <img src="pics/8b798007-e0fb-420c-b981-ead215692417.jpg" width=""/> </div><br>
<div align="center"> <img src="pics/ac929ea3-daca-40ec-9e95-4b2fa6678243.png" width="250px"/> </div><br>

## 联系的多向性

虽然老师可以开设多门课,并且可以教授多名学生,但是对于特定的学生和课程,只有一个老师教授,这就构成了一个三元联系。

<div align="center"> <img src="pics/423f2a40-bee1-488e-b460-8e76c48ee560.png" width=""/> </div><br>

一般只使用二元联系,可以把多元联系转换为二元联系。

<div align="center"> <img src="pics/de9b9ea0-1327-4865-93e5-6f805c48bc9e.png" width=""/> </div><br>
<div align="center"> <img src="pics/5bb1b38a-527e-4802-a385-267dadbd30ba.png" width="350px"/> </div><br>

## 表示子类

用一个三角形和两条线来连接类和子类,与子类有关的属性和联系都连到子类上,而与父类和子类都有关的连到父类上。

<div align="center"> <img src="pics/7ec9d619-fa60-4a2b-95aa-bf1a62aad408.jpg" width=""/> </div><br>
<div align="center"> <img src="pics/14389ea4-8d96-4e96-9f76-564ca3324c1e.png" width="450px"/> </div><br>

# 参考资料

Expand Down

0 comments on commit 7fa7833

Please sign in to comment.