日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

【Mysql优化】索引覆盖

發布時間:2023/12/10 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Mysql优化】索引覆盖 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

索引覆蓋

  是指 如果查詢的列恰好是索引的一部分,那么查詢只需要在索引文件上進行,不需要回行到磁盤再找數據.這種查詢速度非常快,稱為”索引覆蓋”,比平時的查詢少一次到磁盤讀數據的操作。(索引正好覆蓋到查詢的數據)

?

例如下面:

mysql> use exam9; Database changed mysql> desc options; +----------------+---------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------+------+-----+---------+-------+ | optionId | varchar(40) | NO | PRI | NULL | | | questionId | varchar(40) | YES | MUL | NULL | | | optionContent | varchar(2000) | YES | | NULL | | | optionWithTag | varchar(2000) | YES | | NULL | | | optionSequence | varchar(2) | YES | | NULL | | | isAnswer | varchar(2) | YES | | NULL | | | description | varchar(300) | YES | | NULL | | +----------------+---------------+------+-----+---------+-------+ 7 rows in set (0.00 sec)mysql> reset query cache; #清空緩存 Query OK, 0 rows affected (0.00 sec)mysql> set profiling=on;    #打開profiling功能 Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> select optioncontent from options where optionid='000406aa1b89461d8cfd85f b0e5d9e01'; +------------------------+ | optioncontent | +------------------------+ | 基礎工程完畢進行回填后 | +------------------------+ 1 row in set (0.03 sec)mysql> select optionid from options where optionid='000406aa1b89461d8cfd85fb0e5d 9e01'; +----------------------------------+ | optionid | +----------------------------------+ | 000406aa1b89461d8cfd85fb0e5d9e01 | +----------------------------------+ 1 row in set (0.03 sec)mysql> show profiles;  #顯示概要信息 +----------+------------+------------------------------------------------------- ------------------------------+ | Query_ID | Duration | Query| +----------+------------+------------------------------------------------------- ------------------------------+ | 1 | 0.03480675 | select optioncontent from options where optionid='0004 06aa1b89461d8cfd85fb0e5d9e01' | | 2 | 0.03624525 | select optionid from options where optionid='000406aa1 b89461d8cfd85fb0e5d9e01' | +----------+------------+------------------------------------------------------- ------------------------------+ 2 rows in set, 1 warning (0.00 sec)mysql> explainselect optionid from options where optionid='000406aa1b89461d8cfd8 5fb0e5d9e01'\G ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'expla inselect optionid from options where optionid='000406aa1b89461d8cfd85fb0e5d' at line 1 mysql> explain select optionid from options where optionid='000406aa1b89461d8cfd 85fb0e5d9e01'\G #explain分析語句 *************************** 1. row ***************************id: 1select_type: SIMPLEtable: optionspartitions: NULLtype: const possible_keys: PRIMARYkey: PRIMARYkey_len: 122ref: constrows: 1filtered: 100.00Extra: Using index  #表示索引覆蓋 1 row in set, 1 warning (0.03 sec)mysql> explain select optioncontent from options where optionid='000406aa1b89461 d8cfd85fb0e5d9e01'\G    #分析語句 *************************** 1. row ***************************id: 1select_type: SIMPLEtable: optionspartitions: NULLtype: const possible_keys: PRIMARYkey: PRIMARYkey_len: 122ref: constrows: 1filtered: 100.00Extra: NULL 1 row in set, 1 warning (0.03 sec)

?

轉載于:https://www.cnblogs.com/qlqwjy/p/8593076.html

總結

以上是生活随笔為你收集整理的【Mysql优化】索引覆盖的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。