溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

INNODB SYSTEM RECORD infimum和supremum的舉例分析

發(fā)布時(shí)間:2021-11-19 10:44:44 來源:億速云 閱讀:119 作者:iii 欄目:MySQL數(shù)據(jù)庫

這篇文章主要介紹“INNODB SYSTEM RECORD infimum和supremum的舉例分析”,在日常操作中,相信很多人在INNODB SYSTEM RECORD infimum和supremum的舉例分析問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”INNODB SYSTEM RECORD infimum和supremum的舉例分析”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

我們知道在一個(gè)C語言中最后一個(gè)鏈表的NEXT指針指向的NULL空指針,那么這里SUPREMUM實(shí)際就是NULL空指針及0
他們位置固定在塊的94-120字節(jié),其中94-107為infimum 相關(guān)信息,而107到120為supremum相關(guān)信息

info flags              4bits
number of records owned 4bits
order                  13bits
record type             3bits
next record offset      2bytes
"infimum\0"             8bytes (C語言數(shù)組以\0表示結(jié)尾)
以上是infimum固定信息
info flags              4bits
number of records owned 4bits
order                   13bits
record type             3bits
next record offset      2bytes
"supremum"              8bytes
以上是supremum固定信息

我們同樣適用bcview來查看infimum信息,當(dāng)然查看的還是塊3(0開頭實(shí)際是第4個(gè)塊)
bcview km1.ibd 16 94 16|more

current block:00000003--Offset:00094--cnt bytes:13--data is:0100020041696e66696d756d00
1、info flags
這4位(4bits)標(biāo)示是一個(gè)行標(biāo)識(shí),其中binary 0001表示最小的行,其中binary 0010表示是刪除的行,而infimum和supremum行在我測(cè)試數(shù)據(jù)庫中為binary 0000
2、number of records owned 
這4位(4bits)表示在本page directory(槽)中的記錄數(shù),關(guān)于槽的概念后面詳細(xì)探討
3、order
這13位(13bits)表示記錄插入到塊中順序,INFIMUM恒等于0而SPREMUM恒等于1,而數(shù)據(jù)行的ORDER從2開始
4、record type
這3位(3bits)表示記錄的類型,supermum恒等于3及binary 011,infimum恒等于2及binary010,節(jié)點(diǎn)指針為1及001,數(shù)據(jù)行為000
5、next record offset 
這2個(gè)字節(jié) 在INFIMUM中表示的是第一個(gè)行的偏移量這個(gè)偏移量是當(dāng)前記錄的位置+offset,這個(gè)offset直接指向了數(shù)據(jù)而相關(guān)的行頭在offset-n開始n為行頭的開銷。
當(dāng)然supermum為的偏移量就是NULL空指針了。
6、"infimum\0" OR "supremum" 
這沒什么好解釋的就是實(shí)際的ASCII值
我們還是適用我寫工具mysqlblock和bcview進(jìn)行驗(yàn)證

[root@hadoop1 test]# mysqlblock km1.ibd -d
***************************************************
USEAGE: mysqlblock datafile -t/-d                  
This small tool used in study and test database,not
uesd on online database!                           
This tool is used to find how many blocks and types
in specified datafile,Exp:how many undo block in d 
ata file!                                          
QQ:2238980                                         
***************************************************
-t Only Total blocks types in ibdata!              
-d Blocks types detail  in ibdata!                 
***************************************************
FILE SIZE IS : 98304
current read blocks is : 0 --This Block is file space header blocks!
current read blocks is : 1 --This Block is insert buffer bitmap  blocks!
current read blocks is : 2 --This Block is inode blocks!
current read blocks is : 3 --This Block is data blocks( index pages)!
current read blocks is : 4 --This Block is new allocate blocks!
current read blocks is : 5 --This Block is new allocate blocks!
Total Block Status    :
Total  block                   :     6,Total size is: 0.093750 MB
Total undo block               :     0,Total size is: 0.000000 MB
Total inode block              :     1,Total size is: 0.015625 MB
Total insert buffer free blocks:     0,Total size is: 0.000000 MB
Total data(index pages) block  :     1,Total size is: 0.015625 MB
Total new allocate blocks      :     2,Total size is: 0.031250 MB
Total insert buf bitmap blocks :     1,Total size is: 0.015625 MB
Total system blocks            :     0,Total size is: 0.000000 MB
Total transaction system blocks:     0,Total size is: 0.000000 MB
Total file space header blocks :     1,Total size is: 0.015625 MB
Total extrenl disc blocks      :     0,Total size is: 0.000000 MB
Total LOB blocks               :     0,Total size is: 0.000000 MB
Total Unkown blocks            :     0,Total size is: 0.000000 MB

可以看到
current read blocks is : 3 --This Block is data blocks( index pages)!
就是實(shí)際的數(shù)據(jù),因?yàn)槲疫@里只有
mysql> select * from km1;
+------+---------+
| id   | name    |
+------+---------+
|    2 | gaopeng |
|    4 | gaopeng |
|    5 | gaopeng |
|    6 | gaopeng |
|    7 | gaopeng |
|    8 | gaopeng |
+------+---------+
6 rows in set (0.04 sec)

6行數(shù)據(jù),并且是上次測(cè)試留下了,這些數(shù)據(jù)部分是從用的DELETE的空間,當(dāng)然這也就是說,你的INSERT并不一定在文件中是順序存儲(chǔ)的,
因?yàn)閐elete的空間會(huì)被重用。

[root@hadoop1 test]# bcview km1.ibd 16 94 26|more
******************************************************************
This Tool Is Uesed For Find The Data In Binary format(Hexadecimal)
Usage:./bcview file blocksize offset cnt-bytes!                   
file: Is Your File Will To Find Data!                             
blocksize: Is N kb Block.Eg: 8 Is 8 Kb Blocksize(Oracle)!         
                         Eg: 16 Is 16 Kb Blocksize(Innodb)!       
offset:Is Every Block Offset Your Want Start!                                     
cnt-bytes:Is After Offset,How Bytes Your Want Gets!                               
Edtor QQ:22389860!                                                
Used gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)                
******************************************************************
----Current file size is :0.093750 Mb
----Current use set blockszie is 16 Kb
current block:00000000--Offset:00094--cnt bytes:26--data is:00000000ffffffff0000ffffffff000000000000000000030000
current block:00000001--Offset:00094--cnt bytes:26--data is:0000000000000000000000000000000000000000000000000000
current block:00000002--Offset:00094--cnt bytes:26--data is:00000000ffffffff0000ffffffff000005d669d200000003ffff
current block:00000003--Offset:00094--cnt bytes:26--data is:0100020041696e66696d756d0007000b000073757072656d756d
current block:00000004--Offset:00094--cnt bytes:26--data is:0000000000000000000000000000000000000000000000000000
current block:00000005--Offset:00094--cnt bytes:26--data is:0000000000000000000000000000000000000000000000000000

我們只研究數(shù)據(jù)塊current block:00000003的實(shí)際數(shù)據(jù)
current block:00000003--Offset:00094--cnt bytes:26--data is:0100020041696e66696d756d0007000b000073757072656d756d
分解一下:

0100020041696e66696d756d00 為infimum的相關(guān)信息
07000b000073757072656d756d 為SPREMUM的相關(guān)信息

1、info flags
4位
0X0 infimum
0X0 supremum
infimum和supremum行在我測(cè)試數(shù)據(jù)庫中為binary 0000
2、number of records owned 
4位
0X1 infimum   binary 0001  1行
0X7 supremum  binary 0111  7行
3、order
由于13位不能轉(zhuǎn)化為16進(jìn)制直接給出二進(jìn)制binary
infimum 0X0002 兩字節(jié)0000 0000 0000 0010
supermum 0X000b兩字節(jié)0000 0000 0000 1011 
binary 0000 0000 0000 0 infimum  可以看到確實(shí)infimum在這13位上為0
binary 0000 0000 0000 1 supermum 可以看到確實(shí)supermum在這13位上為1

4、record type
infimum  3位為binary 010 及10進(jìn)制的2    可以看到確實(shí)infimum恒等于2及binary  010
supermum 3位為binary 011 及10進(jìn)制的3    可以看到確實(shí)supermum恒等于3及binary 011

5、next record offset
infimum  2個(gè)字節(jié)為 0X0041  這里infimum指向了下一個(gè)行的指針
supermum 2個(gè)字節(jié)為 0X0000  這里supermum為空指針0X0000

那么我們就要看看infimum的指針0X0041是不是指向的數(shù)據(jù)了,
0X0041 十進(jìn)制為65,這個(gè)位置是infimum header 結(jié)束位置相對(duì)偏移量及99
我們知道int類型為4BYTES而我的數(shù)據(jù)'gaopeng'為7字節(jié)
那么就是11字節(jié)
同時(shí)在我們的頁數(shù)據(jù)塊,當(dāng)然我這里就一個(gè)塊當(dāng)然也就是頁塊了
他的數(shù)據(jù)結(jié)構(gòu)實(shí)際如下:
CLUSTER KEY FIELDS 主鍵字節(jié)數(shù),我這里沒有就是ROWID,6字節(jié)
transaction id     固定6字節(jié)
roll pointer       固定7字節(jié)
Non-key fields     就是數(shù)據(jù)的字節(jié)數(shù),我這里就是11字節(jié)了
那么我們可以算出起始位置為99+65=164 查看的字節(jié)數(shù)為 11+6+6+7=30
注意這里的偏移量為65很顯然,這里不是物理的第一行,order 排序的第一行。order就是插入的順序,原來的第一行被我DELETE掉了,空間重用過了。

bcview km1.ibd 16 164 30|more
current block:00000003--Offset:00164--cnt bytes:30--data is:000001cc64260000002d0272d300000d1201108000000267616f70656e67
分解一下數(shù)據(jù)
000001cc6426   ROWID
0000002d0272   transaction id
d300000d120110 roll pointer
80000002       數(shù)據(jù)2,這里8出現(xiàn)在第15位,可能為符號(hào)位
67616f70656e67 數(shù)據(jù)'gaopeng'的ascII值

可以看到?jīng)]有問題,我們找到了他的數(shù)據(jù),由于ROW HEADER是可變的,所以這個(gè)指針指向是數(shù)據(jù)的開頭,而不包含行頭
行頭信息需要計(jì)算offset后像前面偏移N個(gè)字節(jié)開始,當(dāng)然這內(nèi)容以后再討論
關(guān)于行的格式會(huì)在以后的文章中給出,這里重要解釋infimum和supermum,

6、"infimum\0"和"supermum"

這個(gè)沒什么好說的就是ASCII值
696e66696d756d00="infimum\0"
73757072656d756d="supermum"

最后
這里在做一個(gè)測(cè)試試一下 bigint UNSIGNED  類型 
首先測(cè)試bigint是否為8個(gè)字節(jié),同時(shí)測(cè)試符號(hào)位
mysql> create table km15(id   bigint UNSIGNED ,name varchar(20));
Query OK, 0 rows affected (0.15 sec)
mysql> insert into km15 values(10,'gaopeng');
Query OK, 1 row affected (0.02 sec)
同樣不需要主鍵
bcview km15.ibd 16 94 26|more
current block:00000003--Offset:00094--cnt bytes:26--data is:010002001c696e66696d756d0002000b000073757072656d756d
分解數(shù)據(jù)
010002001c696e66696d756d00  infimum
02000b000073757072656d756d  supermum
infimum行的偏移量001c=28
99+28=127   
CLUSTER KEY FIELDS 主鍵字節(jié)數(shù),我這里沒有就是ROWID,6字節(jié)
transaction id     固定6字節(jié)
roll pointer       固定7字節(jié)
Non-key fields     就是數(shù)據(jù)的字節(jié)數(shù),我這里就是8(bigint)+7字節(jié)了=15字節(jié)
bcview km15.ibd 16 127 34|more
current block:00000003--Offset:00127--cnt bytes:34--data is:000001cc680a0000002d0e74e0000080240110000000000000000a67616f70656e67
分解數(shù)據(jù)
000001cc680a
0000002d0e74
e0000080240110
000000000000000a 實(shí)際數(shù)據(jù)10
67616f70656e67   數(shù)據(jù)'goapeng'
沒有問題bigint UNSIGNED為8字節(jié)同時(shí)沒有了符號(hào)位當(dāng)然沒有符號(hào)位存儲(chǔ)的數(shù)據(jù)最大也就是2^64 如果有符號(hào)當(dāng)然少一位
就是-2^32到2^32 如果有C語言的基礎(chǔ)也就不難理解了。

到此,關(guān)于“INNODB SYSTEM RECORD infimum和supremum的舉例分析”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI