MySQL覆蓋索引

2021-10-04 19:47:22 字數 2325 閱讀 6159

1.熟悉什麼是覆蓋索引

2.掌握如何判斷使用了覆蓋索引

使用了id進行查詢,主鍵索引

explain

select

*from employee where id =

13\g;

mysql>

explain

select

*from employee where id =

13\g;**

****

****

****

****

****

****

*1.row***

****

****

****

****

****

****

id: 1

select_type: ******

table: employee

partitions: null

type: const

possible_keys: primary

key: primary

key_len: 4

ref: const

rows: 1

filtered: 100.00

extra: null

1row

inset

,1 warning (

1.83 sec)

error:

no query specified

在extra裡面沒有using

index欄位,說明還是從表裡面取出資料

只查id,有用到覆蓋索引

explain

select id from employee where id =

13\g;

mysql>

explain

select id from employee where id =

13\g;**

****

****

****

****

****

****

*1.row***

****

****

****

****

****

****

id: 1

select_type: ******

table: employee

partitions: null

type: const

possible_keys: primary

key: primary

key_len: 4

ref: const

rows: 1

filtered: 100.00

extra: using

index

1row

inset

,1 warning (

0.00 sec)

查詢姓名,薪水,部門也一樣都用到了覆蓋索引

name,salary,dept

但是如果其中插入了性別***,

mysql>

explain

select name,salary,***,dept from employee where id =

13\g;**

****

****

****

****

****

****

*1.row***

****

****

****

****

****

****

id: 1

select_type: ******

table: employee

partitions: null

type: const

possible_keys: primary

key: primary

key_len: 4

ref: const

rows: 1

filtered: 100.00

extra: null

1row

inset

,1 warning (

0.00 sec)

error:

no query specified

MySQL覆蓋索引呼叫 MySQL 覆蓋索引

什麼是覆蓋索引 建立乙個索引,該索引包含查詢中用到的所有字段,稱為 覆蓋索引 使用覆蓋索引,mysql 只需要通過索引就可以查詢和返回查詢所需要的資料,而不必在使用索引處理資料之後再進行回表操作。覆蓋索引可以一次性完成查詢工作,有效減少io,提高查詢效率。使用示例 查詢語句 select col2,...

MySQL 索引 覆蓋索引

1.什麼是覆蓋索引?概念 查詢語句中所需要的列在索引中,這樣查詢結果在索引的資料結構中查詢即可拿到結果。附加解釋 2.形成覆蓋索引的條件索引分為多種型別,從資料結構上分為 二叉樹 紅黑樹 hash索引 b tree索引,b tree mysql使用的儲存結構 索引的實現可以使用多種資料結構,這裡使用...

mysql覆蓋索引 MySQL 的覆蓋索引與回表

兩大類索引 使用的儲存引擎 mysql5.7 innodb 聚簇索引 如果表設定了主鍵,則主鍵就是聚簇索引 如果表沒有主鍵,則會預設第乙個not null,且唯一 unique 的列作為聚簇索引 以上都沒有,則會預設建立乙個隱藏的row id作為聚簇索引 innodb的聚簇索引的葉子節點儲存的是行記...