Mysql索引研究總結

2023-01-20 17:56:03 字數 1539 閱讀 6044

閒來無事,研究了一下mysql索引,場景如下:

有一張myisam 型別的zt_action表,資料大約230w行,建兩個索引,

create index `read` on zt_action(`read`)

create index `type_id_read` on zt_action(`objecttype,objectid,read`)

create index `actor_action_date` on zt_action(`actor,action,date`)

explain select objecttype from zt_action where objecttype='user' and objectid=1 and `read`='0'    ('using where; using index')     使用索引type_id_read,type為ref

explain select * from zt_action where `read`='3'     ('using index condition')   使用索引read,然後為了select * ,所以進行回表操作

explain select * from zt_action where `read`='0' and objecttype='user'     ('using index condition')   使用索引type_id_read,然後進行回表操作

explain select `read` from zt_action      ('using index')  未使用索引,但是遍歷了索引表read

explain select `read` from zt_action where `read`='0'       ('using where; using index')  使用索引read

explain select `read` from zt_action where `read`='0' and objecttype='user'    ('using index condition; using where') ('using where; using index')type_id_read  使用索引read, 這個不清楚了

explain select `read` from zt_action where objectid=1   ('using where; using index')  未使用索引,但是遍歷索引表type_id_read

explain select `date` from zt_action where objectid=1   ('using where')  未使用索引,全表掃描

explain select `read` from zt_action where objecttype='user'   ('using where; using index')  使用了索引type_id_read

explain select `date` from zt_action where `action` like '%ct%';    ('using where; using index')   未使用索引,但是遍歷了索引表actor_action_date

索引總結 mysql

選擇索引和編寫利用這些索引的查詢中,如下三原則始終需要記住 單行訪問是很慢的 意思就是如果讀取一個資料庫只是為了讀取一行資料,那麼這就是不會高效,這就需要使用索引,或者讀取的塊中包含更多需要的行資料。按照順序訪問範圍資料是很快的 按照順序訪問範圍資料是很快的原因有兩個 一個是順序i o不需要多次磁碟...

Mysql 索引總結

索引 index 是幫助mysql高效獲取資料的 資料結構 下邊是自己整理的資料與自己的學習總結,做一個彙總。一.真的有必要使用索引嗎?不是每一個效能問題都可以通過建立一個索引來解決 有很多其它解決效能問題的方式 a 各個應用層的快取,b 調優資料庫引數和緩衝區大小,c 調優資料庫連線池大小或者執行...

MySQL索引 總結

索引 排好序的快速查詢的資料結構 mysql是外掛式儲存引擎,基於表的rdb,不同的表可以選擇不同儲存引擎 儲存引擎 myisam innodb ndb,memory 阿里自己開發的alisql myisam不支援事務,支援表鎖支援全文索引,查詢效率非常高 innodb支援事務,行鎖 電商專案 訂單...