溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql中如何進行聯合索引優化

發布時間:2021-11-16 15:40:25 來源:億速云 閱讀:373 作者:柒染 欄目:MySQL數據庫

今天就跟大家聊聊有關mysql中如何進行聯合索引優化,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

 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條件中兩個字段的基數,建立聯合索引會有指數級提升
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 |

掃描行數降低為3

看完上述內容,你們對mysql中如何進行聯合索引優化有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女