MySQL8.0倒序索引數(shù)據(jù)的數(shù)據(jù)排列方式是什么

本篇內(nèi)容主要講解“MySQL8.0倒序索引數(shù)據(jù)的數(shù)據(jù)排列方式是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“MySQL8.0倒序索引數(shù)據(jù)的數(shù)據(jù)排列方式是什么”吧!

創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),南充網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:南充等地區(qū)。南充做網(wǎng)站價(jià)格咨詢:18982081108

一、準(zhǔn)備數(shù)據(jù)

mysql> create table tab_desc
    -> (id1 int,
    ->  id2 int,
    ->  key(id1),
    ->  key(id2 desc));
Query OK, 0 rows affected (1.29 sec)
mysql> select * from tab_desc;
+------+------+| id1  | id2  |
+------+------+
|    1 |    1 ||    2 |    2 |
|    3 |    3 ||    4 |    4 |
|    5 |    5 ||    6 |    6 |
|    7 |    7 |+------+------+

二、通過執(zhí)行計(jì)劃證明

這個(gè)比較簡單我們使用using index type index 來訪問索引發(fā)現(xiàn)他們確實(shí)是相反

mysql> desc select id2 from tab_desc;
+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table    | partitions | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | tab_desc | NULL       | index | NULL          | id2  | 5       | NULL |    7 |   100.00 | Using index |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+1 row in set, 1 warning (0.11 sec)
mysql> select id2 from tab_desc;
+------+| id2  |+------+|    7 ||    6 ||    5 ||    4 ||    3 ||    2 ||    1 |+------+7 rows in set (0.00 sec)
mysql> desc select id1 from tab_desc;
+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+| id | select_type | table    | partitions | type  | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | tab_desc | NULL       | index | NULL          | id1  | 5       | NULL |    7 |   100.00 | Using index |+----+-------------+----------+------------+-------+---------------+------+---------+------+------+----------+-------------+1 row in set, 1 warning (0.00 sec)
mysql> select id1 from tab_desc;
+------+| id1  |+------+|    1 ||    2 ||    3 ||    4 ||    5 ||    6 ||    7 |+------+7 rows in set (0.00 sec)

三、通過工具證明

執(zhí)行 ./innblock tab_desc.ibd scan 16得到結(jié)果
===INDEX_ID:136level0 total block is (1)
block_no:         4,level:   0|*|
===INDEX_ID:137level0 total block is (1)
block_no:         5,level:   0|*|
===INDEX_ID:138level0 total block is (1)
block_no:         6,level:   0|*|
通過INNODB_INDEXES可以看到這兩個(gè)索引對(duì)應(yīng)的ID確實(shí)是137/138
|      136 | GEN_CLUST_INDEX |     1059 |    1 |        5 |       4 |     2 |              50 |
|      137 | id1             |     1059 |    0 |        2 |       5 |     2 |              50 ||      138 | id2             |     1059 |    0 |        2 |       6 |     2 |              50 |
通過命令 ./innblock tab_desc.ibd 5 16和 ./innblock tab_desc.ibd 6 16可以獲得他們的邏輯鏈表信息如下:
id1
==== Block list info ====
-----Total used rows:9 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:142 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0(4) normal record offset:158 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0(5) normal record offset:174 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0(6) normal record offset:190 heapno:6 n_owned 0,delflag:N minflag:0 rectype:0(7) normal record offset:206 heapno:7 n_owned 0,delflag:N minflag:0 rectype:0(8) normal record offset:222 heapno:8 n_owned 0,delflag:N minflag:0 rectype:0 (9) SUPREMUM record offset:112 heapno:1 n_owned 8,delflag:N minflag:0 rectype:3id2
==== Block list info ====
-----Total used rows:9 used rows list(logic):
(1) INFIMUM record offset:99 heapno:0 n_owned 1,delflag:N minflag:0 rectype:2(2) normal record offset:222 heapno:8 n_owned 0,delflag:N minflag:0 rectype:0 (3) normal record offset:206 heapno:7 n_owned 0,delflag:N minflag:0 rectype:0(4) normal record offset:190 heapno:6 n_owned 0,delflag:N minflag:0 rectype:0(5) normal record offset:174 heapno:5 n_owned 0,delflag:N minflag:0 rectype:0(6) normal record offset:158 heapno:4 n_owned 0,delflag:N minflag:0 rectype:0(7) normal record offset:142 heapno:3 n_owned 0,delflag:N minflag:0 rectype:0(8) normal record offset:126 heapno:2 n_owned 0,delflag:N minflag:0 rectype:0  (9) SUPREMUM record offset:112 heapno:1 n_owned 8,delflag:N minflag:0 rectype:3

我們可以看到ID1普通索引邏輯鏈表信息為:
INFIMUM ->126 ->142 ->158 .....->SUPREMUM
而我們的反向索引邏輯鏈表信息為:
INFIMUM ->222->206 ->190 .....->SUPREMUM

那么我們分別來解讀下數(shù)據(jù)因?yàn)槠胀ㄋ饕臄?shù)據(jù)域排列方式就是:數(shù)據(jù)+主鍵 而int代表的是4字節(jié)那么
id1的數(shù)據(jù)就是 (這里用到了一個(gè)自己的工具bcview方便觀察,當(dāng)然非要肉眼擼也是也可以的用hexdump):

  • 第一行 126字節(jié)后的4字節(jié)為:80000001
    current block:00000005--Offset:00126--cnt bytes:04--data is:80000001

  • 第二行 142字節(jié)后的4個(gè)字節(jié):80000002
    current block:00000005--Offset:00142--cnt bytes:04--data is:80000002

  • 第三行 158字節(jié)后的4個(gè)字節(jié):80000003
    current block:00000005--Offset:00158--cnt bytes:04--data is:80000003

  • 第四行 174字節(jié)后的4個(gè)字節(jié):80000004
    current block:00000005--Offset:00174--cnt bytes:04--data is:80000004

后面的我就不查詢了可以看到是從小到大的。

接下來我們分解下倒序索引的數(shù)據(jù):

  • 第一行 222字節(jié)后的4字節(jié)為: 80000007
    current block:00000006--Offset:00222--cnt bytes:04--data is:80000007

  • 第二行 206字節(jié)后的4個(gè)字節(jié): 80000006
    current block:00000006--Offset:00206--cnt bytes:04--data is:80000006

  • 第三行 190字節(jié)后的4個(gè)字節(jié): 80000005
    current block:00000006--Offset:00190--cnt bytes:04--data is:80000005

  • 第四行 174字節(jié)后的4個(gè)字節(jié): 80000004
    current block:00000006--Offset:00174--cnt bytes:04--data is:80000004

因此我們得到驗(yàn)證,對(duì)于倒序索引而言其數(shù)據(jù)是在INFIMUM和SUPREMUM降序排列的。

到此,相信大家對(duì)“MySQL8.0倒序索引數(shù)據(jù)的數(shù)據(jù)排列方式是什么”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

分享題目:MySQL8.0倒序索引數(shù)據(jù)的數(shù)據(jù)排列方式是什么
本文URL:http://muchs.cn/article28/gdijcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、建站公司、小程序開發(fā)網(wǎng)站營銷、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)