mysql中如何進行聯(lián)合索引優(yōu)化

今天就跟大家聊聊有關(guān)MySQL中如何進行聯(lián)合索引優(yōu)化,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)提供高防服務(wù)器、云服務(wù)器、香港服務(wù)器、德陽服務(wù)器托管

 explain select Fid from t_cyou_view_records where Fanchormasterid = 20237 and Froleid = 15081 and Fouttime is null order by Fentertime desc limit 1;

| id | select_type | table               | type | possible_keys | key  | key_len | ref  | rows    | Extra                       |

|  1 | SIMPLE      | t_cyou_view_records | ALL  | NULL          | NULL | NULL    | NULL | 1709800 | Using where; Using filesort |


看了where條件中兩個字段的基數(shù),建立聯(lián)合索引會有指數(shù)級提升
show index from t_cyou_view_records
    -> ;

| Table               | Non_unique | Key_name  | Seq_in_index | Column_name     | Collation | Cardinality | Sub_part | Packed | Null | Index_type | C

| t_cyou_view_records |          0 | PRIMARY   |            1 | Fid             | A         |     1710010 |     NULL | NULL   |      | BTREE      |  
| t_cyou_view_records |          1 | idx_tcvr  |            1 | Fanchormasterid | A         |         132 |     NULL | NULL   | YES  | BTREE      |  
| t_cyou_view_records |          1 | idx_tcvrf |            1 | Froleid         | A         |       58965 |     NULL | NULL   | YES  | BTREE      |  

alter table t_cyou_view_records add index idx_tcvrf(Froleid,Fanchormasterid);
Query OK, 0 rows affected (7.79 sec)
Records: 0  Duplicates: 0  Warnings: 0

explain select Fid from t_cyou_view_records where Fanchormasterid = 20237 and Froleid = 15081 and Fouttime is null order by Fentertime desc limit 1;

| id | select_type | table               | type | possible_keys | key       | key_len | ref         | rows | Extra                       |

|  1 | SIMPLE      | t_cyou_view_records | ref  | idx_tcvrf     | idx_tcvrf | 18      | const,const |    3 | Using where; Using filesort |

掃描行數(shù)降低為3

看完上述內(nèi)容,你們對mysql中如何進行聯(lián)合索引優(yōu)化有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

本文名稱:mysql中如何進行聯(lián)合索引優(yōu)化
分享鏈接:http://www.muchs.cn/article10/ishego.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、定制網(wǎng)站、關(guān)鍵詞優(yōu)化、用戶體驗動態(tài)網(wǎng)站、微信小程序

廣告

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

網(wǎng)站托管運營