/***********************************************************************//** 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 undo entry within page */ { ... ut_ad(roll_ptr < (1ULL << 56)); *offset = (ulint) roll_ptr & 0xFFFF; //获取低16位 为OFFSET roll_ptr >>= 16; //右移16位 *page_no = (ulint) roll_ptr & 0xFFFFFFFF;//获取32位为 page no roll_ptr >>= 32;//右移32位 *rseg_id = (ulint) roll_ptr & 0x7F;//获取7位为segment id roll_ptr >>= 7;//右移7位 *is_insert = (ibool) roll_ptr; /* TRUE==1 *///最后一位 } 二、建立测试表 为了解决文中开头的几个问题,我们来建立测试表如下:
drop table baguait1; create table baguait1(id int primary key,c1 varchar(20) ,c2 varchar(20),c3 char(20)) ENGINE=InnoDB DEFAULT CHARSET=utf8; alter table baguait1 add key(c1); insert into baguait1 values(1,NULL,'gaopeng','gaopeng'); insert into baguait1 values(2,'gaopeng',NULL,'gaopeng'); insert into baguait1 values(3,'gaopeng',NULL,NULL); insert into baguait1 values(4,'a',NULL,NULL); mysql> select * from baguait1; +----+---------+---------+---------+ | id | c1 | c2 | c3 | +----+---------+---------+---------+ | 1 | NULL | gaopeng | gaopeng | | 2 | gaopeng | NULL | gaopeng | | 3 | gaopeng | NULL | NULL | | 4 | a | NULL | NULL | +----+---------+---------+---------+ 4 rows in set (0.01 sec) 我们发现这里实际上除了rowid问题还不能包含,其他都包含了,接下来我们使用innblock进行扫描。如下:
1、扫描数据文件找到主键和普通索引数据块
[root@gp1 test]# ./innblock baguait1.ibd scan 16 ··· Datafile Total Size:114688 ===INDEX_ID:323 level0 total block is (1) block_no: 3,level: 0|*| ===INDEX_ID:324 level0 total block is (1) block_no: 4,level: 0|*| 这里实际上323就是聚集索引,324就是普通索引,它们数据块对应是3和4。
2、扫描聚集索引记录
[root@gp1 test]# ./innblock baguait1.ibd 3 16 链表部分: ==== Block list info ==== -----Total used rows:6 used rows list(logic): (1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2 (2) normal record offset:128 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0 (3) normal record offset:180 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0 (4) normal record offset:231 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0 (5) normal record offset:262 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0 (6) SUPREMUM record offset:112 heapno:1 n_owned 5,delflag:N minflag:0 rectype:3 -----Total used rows:6 used rows list(phy): (1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2 (2) SUPREMUM record offset:112 heapno:1 n_owned 5,delflag:N minflag:0 rectype:3 (3) normal record offset:128 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0 (4) normal record offset:180 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0 (5) normal record offset:231 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0 (6) normal record offset:262 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0 3、扫描普通索引记录 ``` [root @gp1 test]# ./innblock baguait1.ibd 4 16
链表部分: ==== Block list info ==== ——-Total used rows:6 used rows list(logic): (1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2 (2) normal record offset:126 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0 (3) normal record offset:173 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0 (4) normal record offset:137 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0 (5) normal record offset:155 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0 (6) SUPREMUM record offset:112 heapno:1 n_owned 5,delflag:N minflag:0 rectype:3 ——-Total used rows:6 used rows list(phy): (1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2 (2) SUPREMUM record offset:112 heapno:1 n_owned 5,delflag:N minflag:0 rectype:3 (3) normal record offset:126 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0 (4) normal record offset:137 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0 (5) normal record offset:155 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0 (6) normal record offset:173 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0