久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

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

148次閱讀
沒有評論

共計 1428 個字符,預計需要花費 4 分鐘才能閱讀完成。

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

 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 中如何進行聯合索引優化有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注丸趣 TV 行業資訊頻道,感謝大家的支持。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計1428字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 建昌县| 普定县| 扶沟县| 宜春市| 广河县| 进贤县| 汉寿县| 陇西县| 石屏县| 清丰县| 景谷| 临高县| 手机| 泰宁县| 普兰县| 察隅县| 阜城县| 汉寿县| 武义县| 平塘县| 泉州市| 寿光市| 柳河县| 涿鹿县| 清水县| 衡阳县| 安泽县| 阳谷县| 湛江市| 清水河县| 东光县| 林芝县| 淮阳县| 同江市| 休宁县| 婺源县| 衡东县| 珠海市| 缙云县| 怀仁县| 邵阳县|