-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Q10Viking
committed
Mar 23, 2024
1 parent
e6a613c
commit 77efb87
Showing
5 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
sidebarDepth: 3 | ||
sidebar: auto | ||
prev: | ||
text: Back To 目录 | ||
link: /MySQL/ | ||
typora-root-url: ..\.vuepress\public | ||
--- | ||
|
||
|
||
|
||
|
||
|
||
**首先,**获取事务的回滚指针或Undo Log的起始位置。 | ||
|
||
从Undo Log的末尾开始逆向扫描,按照事务操作的逆序依次处理每个日志记录。 | ||
|
||
**然后,**针对 INSERT 操作,执行 DELETE 操作来撤销插入的数据。对于 UPDATE 操作,使用Undo Log 中记录的旧值将数据还原到之前的状态。 | ||
|
||
在回滚过程中,对于已经提交的其他事务所做的修改需要跳过,只处理属于当前回滚事务的 Undo Log 记录。 | ||
|
||
按照逆序依次处理所有的日志记录,直到达到回滚指针位置或 Undo Log 的起始位置。 | ||
|
||
**回滚完成后,**清除或标记已回滚的 Undo Log 记录。 | ||
|
||
总体而言,事务回滚是通过执行 Undo Log 中记录的反向操作,将事务的修改操作撤销,恢复到事务开始前的状态。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
sidebarDepth: 3 | ||
sidebar: auto | ||
prev: | ||
text: Back To 目录 | ||
link: /MySQL/ | ||
typora-root-url: ..\.vuepress\public | ||
--- | ||
|
||
|
||
|
||
1. **数据存储方式:**在B树中,每个节点都包含键和对应的值,叶子节点存储了实际的数据记录;而B+树中,只有叶子节点存储了实际的数据记录,非叶子节点只包含键信息和子节点的指针。 | ||
2. **数据检索方式:**在B树中,由于非叶子节点也存储了数据,所以查询时可以直接在非叶子节点找到对应的数据,具有更短的查询路径;而B+树的所有数据都存储在叶子节点上,只有通过叶子节点才能获取到完整的数据。 | ||
3. **范围查询效率:**由于B+树的所有数据都存储在叶子节点上,并且**叶子节点之间使用链表连接,所以范围查询的效率较高**。而在B树中,范围查询需要通过遍历多个层级的节点,效率相对较低 | ||
4. **适用场景:**B树适合进行随机读写操作,因为每个节点都包含了数据;而B+树适合进行范围查询和顺序访问,因为数据都存储在叶子节点上,并且叶子节点之间使用链表连接,有利于顺序遍历。 | ||
|
||
**总结来说:** B树和B+树在数据存储方式、数据检索方式、范围查询效率以及适用场景方面存在区别。B树适合随机读写操作,而B+树适合范围查询和顺序访问。在实际应用中,根据不同的场景和需求选择合适的树结构可以带来更高效的数据处理和索引操作。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
sidebarDepth: 3 | ||
sidebar: auto | ||
prev: | ||
text: Back To 目录 | ||
link: /MySQL/ | ||
typora-root-url: ..\.vuepress\public | ||
--- | ||
|
||
|
||
|
||
1. **IN关键字:**使用 IN 条件时,我们提供一个固定的值列表,然后将其与指定列的值进行比较。如果列中的值与列表中的任何一个值匹配,就会返回结果。IN 条件适合用于确定某个字段的值是否在给定的值列表中。 | ||
|
||
```sql | ||
SELECT * FROM table_name WHERE column_name IN (value1, value2, value3); | ||
# 如果 column_name 的值与 value1、value2 或 value3 中的任何一个相匹配,那么这条记录将会被返回。 | ||
``` | ||
|
||
2. **EXISTS关键字:**使用 EXISTS 条件时,我们需要指定一个子查询。查询的结果并不重要,而是判断子查询是否返回了至少一行结果。如果子查询返回了结果,EXISTS 条件就会被认为是满足的。EXISTS 条件适合用于判断某个条件是否至少存在于子查询的结果中。 | ||
|
||
```sql | ||
SELECT * FROM table_name WHERE EXISTS (SELECT * FROM another_table WHERE condition); | ||
# 如果子查询(SELECT * FROM another_table WHERE condition)返回了至少一行结果,那么主查询中的记录将会被返回。 | ||
``` | ||
|
||
## 小结 | ||
|
||
- 使用 IN 条件时,比较的是指定列的值是否在给定的值列表中。 | ||
- 使用 EXISTS 条件时,判断的是子查询是否返回了至少一行结果。 |