怎么理解MySQL中Innodb DB_ROLL_PTR指针
本篇内容主要讲解“怎么理解MySQL中Innodb DB_ROLL_PTR指针”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么理解MySQL中Innodb DB_ROLL_PTR指针”吧!
一、引入我们知道每一条记录在聚集索引上都有如下的分布:
rowid(主键)+DB_TRX_ID+DB_ROLL_PTR+其他字段
这样格式其中DB_TRX_ID+DB_ROLL_PTR作为一致性读的关键信息存储下来,其中DB_TRX_ID在存储上占用6字节,DB_ROLL_PTR在存储上占用7字节。那么DB_ROLL_PTR是如何解析到undo上的呢,这也是一位朋友问的问题。
下面是trx0types.h中对这部分的定义
/**Rowidentifier(DB_ROW_ID,DATA_ROW_ID)*/typedefib_id_trow_id_t;/**Transactionidentifier(DB_TRX_ID,DATA_TRX_ID)*/typedefib_id_ttrx_id_t;/**Rollbackpointer(DB_ROLL_PTR,DATA_ROLL_PTR)*/typedefib_id_troll_ptr_t;
而ib_id_t实际上都是64位非负整数
typedefunsigned__int64ib_uint64_t;二、函数流程
我大概看了一下流程如下:
trx_undo_prev_version_build//Buildapreviousversionofaclusteredindexrecord->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的解析工作获取segmentid\pageno\offset->开MTR获取latch准备拷贝->拷贝trx_undo_rec_copy->提交MTR
实际上解析工具由trx_undo_decode_roll_ptr 完成。
三、实际解析其实解析挺简单,都是写死了的。
/***********************************************************************//**Decodesarollpointer.*///从高位到低位依次是第1位是否是insert//第2到8位是segmentid//第9到40位为pageno//第41位到56位为OFFSETUNIV_INLINEvoidtrx_undo_decode_roll_ptr(/*=====================*/roll_ptr_troll_ptr,/*!<in:rollpointer*/ibool*is_insert,/*!<out:TRUEifinsertundolog*/ulint*rseg_id,/*!<out:rollbacksegmentid*/ulint*page_no,/*!<out:pagenumber*/ulint*offset)/*!<out:offsetoftheundoentrywithinpage*/{#ifDATA_ROLL_PTR_LEN!=7#error"DATA_ROLL_PTR_LEN!=7"#endif#ifTRUE!=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位为pagenoroll_ptr>>=32;//右移32位*rseg_id=(ulint)roll_ptr&0x7F;//获取7位为segmentidroll_ptr>>=7;//右移7位*is_insert=(ibool)roll_ptr;/*TRUE==1*///最后一位}
到此,相信大家对“怎么理解MySQL中Innodb DB_ROLL_PTR指针”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。