From d4bf768fe3efdb281e70682a24cace48b01e1f52 Mon Sep 17 00:00:00 2001 From: asahi Date: Thu, 14 Aug 2025 21:00:40 +0800 Subject: [PATCH] =?UTF-8?q?doc:=20=E9=98=85=E8=AF=BBmysql=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mysql/mysql文档/mysql_事务.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mysql/mysql文档/mysql_事务.md b/mysql/mysql文档/mysql_事务.md index f25c479..c3ef1b4 100644 --- a/mysql/mysql文档/mysql_事务.md +++ b/mysql/mysql文档/mysql_事务.md @@ -538,4 +538,15 @@ delete from t where a=1; 是否可以对记录进行物理删除由purge来决定,若某行记录不被其他任何事务引用,可以执行物理delete操作。 #### history -innodb存储引擎中维护了一个history列表,其`根据事务的提交顺序`对undo log进行链接,`在history list中,先提交的事务其undo log位于history list的尾端`。 \ No newline at end of file +innodb存储引擎中维护了一个history列表,其`根据事务的提交顺序`对undo log进行链接,`在history list中,先提交的事务其undo log位于history list的尾端`。 + +Mysql undo log_mysql undolog-CSDN博客 + +##### history的purge流程 +已知,先提交的事务位于history list的尾端,故而,purge操作会从尾端开始查找需要被清理的记录。以上图为例,purge操作执行流程如下: +- 从尾端找到第一个需要被清理的记录,此处为trx1 +- 清理完trx1之后,其会在trx 1的undo log为位于的undo page中继续查找是否可清空其他记录,此处可以找到`trx3`,`trx5被其他事务引用不能清理 +- 再次去history list中查找,找到trx2,清理trx2 +- 找到trx2 undo log所在的undo页,然后清理trx 6和trx 4 + +上述流程中,purge会首先从history list中查找undo log,然后会随便清除undo log位于的undo page中其他可以被清理的undo log,`这样能够减少page的随机访问次数,提高性能`。