当前位置:
首页 >
MySQL:Innodb DB_ROLL_PTR指针解析
发布时间:2025/4/16
61
豆豆
生活随笔
收集整理的这篇文章主要介绍了
MySQL:Innodb DB_ROLL_PTR指针解析
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
源码版本5.7.22
此处简单记录一下DB_ROLL_PTR指针解析的方法,水平有限,如果有误请谅解。
一、引入
我们知道每一条记录在聚集索引上都有如下的分布:
- rowid(主键)+DB_TRX_ID+DB_ROLL_PTR+其他字段
这样格式其中DB_TRX_ID+DB_ROLL_PTR作为MVCC的关键信息存储下来,其中DB_TRX_ID在存储上占用6字节,DB_ROLL_PTR在存储上占用7字节。那么DB_ROLL_PTR是如何解析到undo上的呢,这也是一位朋友问的问题。
下面是trx0types.h中对这部分的定义
/** Row identifier (DB_ROW_ID, DATA_ROW_ID) */ typedef ib_id_t row_id_t; /** Transaction identifier (DB_TRX_ID, DATA_TRX_ID) */ typedef ib_id_t trx_id_t; /** Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR) */ typedef ib_id_t roll_ptr_t;而ib_id_t实际上都是64位非负整数
typedef unsigned __int64 ib_uint64_t;二、函数流程
我大概看了一下流程如下:
trx_undo_prev_version_build //Build a previous version of a clustered index record->roll_ptr = row_get_rec_roll_ptr(rec, index, offsets); //获取rollback 指针->rec_trx_id = row_get_rec_trx_id(rec, index, offsets); //获取TRX_ID->trx_undo_get_undo_rec(roll_ptr, rec_trx_id, heap, is_redo_rseg,index->table->name, &undo_rec))//此处获取前版本,获取后放到undo_rec中->trx_undo_get_undo_rec_low(roll_ptr, heap, is_redo_rseg); //undo_rec作为传出参数。传出访问到的undo->trx_undo_decode_roll_ptr //做roll_ptr的解析工作获取segment id\page no\offset->开MTR获取latch准备拷贝->拷贝trx_undo_rec_copy->提交MTR实际上解析工具由trx_undo_decode_roll_ptr 完成。
三、实际解析
其实解析挺简单,都是写死了的。
/***********************************************************************//** Decodes a roll pointer. */ //从高位到低位依次是 第1位是否是insert //第2到8位是segmentid//第9到40位为page no //第41位到56位为OFFSET UNIV_INLINE void trx_undo_decode_roll_ptr( /*=====================*/roll_ptr_t roll_ptr, /*!< in: roll pointer */ibool* is_insert, /*!< out: TRUE if insert undo log */ulint* rseg_id, /*!< out: rollback segment id */ulint* page_no, /*!< out: page number */ulint* offset) /*!< out: offset of the undoentry within page */ { #if DATA_ROLL_PTR_LEN != 7 # error "DATA_ROLL_PTR_LEN != 7" #endif #if TRUE != 1 # error "TRUE != 1" #endifut_ad(roll_ptr < (1ULL << 56));*offset = (ulint) roll_ptr & 0xFFFF; //获取低16位 为OFFSETroll_ptr >>= 16; //右移16位*page_no = (ulint) roll_ptr & 0xFFFFFFFF;//获取32位为 page noroll_ptr >>= 32;//右移32位*rseg_id = (ulint) roll_ptr & 0x7F;//获取7位为segment idroll_ptr >>= 7;//右移7位*is_insert = (ibool) roll_ptr; /* TRUE==1 *///最后一位 }参考注释。自行理解。
作者微信号码:gp_22389860
总结
以上是生活随笔为你收集整理的MySQL:Innodb DB_ROLL_PTR指针解析的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: go设计模式之代理模式
- 下一篇: ORA-03001,GATHER_TAB