1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網營銷解決方案
      什么是MySQL索引提示-創(chuàng)新互聯(lián)

      本篇內容介紹了“什么是MySQL索引提示”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

      長沙ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

            SQL提示,是優(yōu)化數據庫的一個重要手段,簡單來說,就是在SQL語句中加入一些人為的提示來達到優(yōu)化操作的目的。MySQL數據庫支持索引提示(INDEX HINT)顯式的告訴優(yōu)化器使用了哪個索引。有以下幾種情況可能用到索引提示:

      1、MySQL數據庫的優(yōu)化器錯誤的選擇了某個索引,導致SQL運行很慢。這個在情況比較少見。優(yōu)化器在絕大部分情況下工作的非常有效和正確。

      2、某些SQL語句可以選擇的索引非常多,這時優(yōu)化器選擇執(zhí)行計劃時間的開銷可能會大于SQL語句本身。例如優(yōu)化器分析Range查詢本身就是比較耗時的操作。這時DBA或開發(fā)人員分析最優(yōu)的索引選擇,通過index hint來強制使優(yōu)化器不進行各個路徑的成本分析直接選擇指定的索引來完成查詢。

      index hint種類

      MySql共有三種索引提示,分別是:USE INDEX、IGNORE INDEX和FORCE INDEX,他們之間的區(qū)別是:

      1、use index:use index告訴MySql用列表中的其中一個索引去做本次查詢,就可以讓MySQL不再考慮其他可用的索引建議MySQL用這些索引,但是MySQL不一定會用。

      MySQL > show create table test2 \G
      *************************** 1. row ***************************
             Table: test2
      Create Table: CREATE TABLE `test2` (
        `id` bigint(16) NOT NULL AUTO_INCREMENT,
        `order_seq` bigint(16) NOT NULL,
        `order_type` int(11) DEFAULT NULL,
        `order_flag` int(11) DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `idx_id` (`id`),
        KEY `idx_id_orderseq` (`id`,`order_seq`),
        KEY `idx_order_seq` (`order_seq`)
      ) ENGINE=InnoDB AUTO_INCREMENT=15002212 DEFAULT CHARSET=utf8mb4
      1 row in set (0.00 sec)
      MySQL > explain select * from test2 where id>10000 and id<1000000;
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      | id | select_type | table | partitions | type  | possible_keys                  | key     | key_len | ref  | rows    | filtered | Extra       |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      |  1 | SIMPLE      | test2 | NULL       | range | PRIMARY,idx_id,idx_id_orderseq | PRIMARY | 8       | NULL | 2021716 |   100.00 | Using where |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      MySQL > explain select * from test2 use index(idx_id) where id>10000 and id<100000;
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+--------+----------+-----------------------+
      | id | select_type | table | partitions | type  | possible_keys | key    | key_len | ref  | rows   | filtered | Extra                 |
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+--------+----------+-----------------------+
      |  1 | SIMPLE      | test2 | NULL       | range | idx_id        | idx_id | 8       | NULL | 180580 |   100.00 | Using index condition |
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+--------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)
      MySQL > explain select * from test2 use index(idx_order_seq) where id=10000;
      +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows     | filtered | Extra       |
      +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+
      |  1 | SIMPLE      | test2 | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 14611349 |     0.00 | Using where |
      +----+-------------+-------+------------+------+---------------+------+---------+------+----------+----------+-------------+
      1 row in set, 1 warning (0.01 sec)

      2、ignore index:ignore index告訴mysql不要使用某些索引去做本次查詢

      MySQL > show create table test2 \G
      *************************** 1. row ***************************
             Table: test2
      Create Table: CREATE TABLE `test2` (
        `id` bigint(16) NOT NULL AUTO_INCREMENT,
        `order_seq` bigint(16) NOT NULL,
        `order_type` int(11) DEFAULT NULL,
        `order_flag` int(11) DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `idx_id` (`id`),
        KEY `idx_id_orderseq` (`id`,`order_seq`),
        KEY `idx_order_seq` (`order_seq`)
      ) ENGINE=InnoDB AUTO_INCREMENT=15002212 DEFAULT CHARSET=utf8mb4
      1 row in set (0.00 sec)
      MySQL > explain select * from test2 where id>10000 and id<1000000;
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      | id | select_type | table | partitions | type  | possible_keys                  | key     | key_len | ref  | rows    | filtered | Extra       |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      |  1 | SIMPLE      | test2 | NULL       | range | PRIMARY,idx_id,idx_id_orderseq | PRIMARY | 8       | NULL | 2021716 |   100.00 | Using where |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      MySQL > explain select * from test2 ignore index(primary) where id>10000 and id<1000000;
      +----+-------------+-------+------------+-------+------------------------+--------+---------+------+---------+----------+-----------------------+
      | id | select_type | table | partitions | type  | possible_keys          | key    | key_len | ref  | rows    | filtered | Extra                 |
      +----+-------------+-------+------------+-------+------------------------+--------+---------+------+---------+----------+-----------------------+
      |  1 | SIMPLE      | test2 | NULL       | range | idx_id,idx_id_orderseq | idx_id | 8       | NULL | 1971862 |   100.00 | Using index condition |
      +----+-------------+-------+------------+-------+------------------------+--------+---------+------+---------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)

      3、force index:強制MySQL使用一個特定的索引

      MySQL > show create table test2 \G
      *************************** 1. row ***************************
             Table: test2
      Create Table: CREATE TABLE `test2` (
        `id` bigint(16) NOT NULL AUTO_INCREMENT,
        `order_seq` bigint(16) NOT NULL,
        `order_type` int(11) DEFAULT NULL,
        `order_flag` int(11) DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `idx_id` (`id`),
        KEY `idx_id_orderseq` (`id`,`order_seq`),
        KEY `idx_order_seq` (`order_seq`)
      ) ENGINE=InnoDB AUTO_INCREMENT=15002212 DEFAULT CHARSET=utf8mb4
      1 row in set (0.00 sec)
      MySQL > explain select * from test2 where id>10000 and id<1000000;
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      | id | select_type | table | partitions | type  | possible_keys                  | key     | key_len | ref  | rows    | filtered | Extra       |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      |  1 | SIMPLE      | test2 | NULL       | range | PRIMARY,idx_id,idx_id_orderseq | PRIMARY | 8       | NULL | 2021716 |   100.00 | Using where |
      +----+-------------+-------+------------+-------+--------------------------------+---------+---------+------+---------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      MySQL > explain select * from test2 force index(idx_id) where id>10000 and id<1000000;
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-----------------------+
      | id | select_type | table | partitions | type  | possible_keys | key    | key_len | ref  | rows    | filtered | Extra                 |
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-----------------------+
      |  1 | SIMPLE      | test2 | NULL       | range | idx_id        | idx_id | 8       | NULL | 1971862 |   100.00 | Using index condition |
      +----+-------------+-------+------------+-------+---------------+--------+---------+------+---------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)

      “什么是MySQL索引提示”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)-成都網站建設公司網站,小編將為大家輸出更多高質量的實用文章!


      網站標題:什么是MySQL索引提示-創(chuàng)新互聯(lián)
      本文URL:http://www.ef60e0e.cn/article/csocse.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        荥阳市| 淮安市| 和平区| 迁安市| 朝阳县| 治县。| 资中县| 牟定县| 五河县| 玉溪市| 湖州市| 伊春市| 崇阳县| 万州区| 临汾市| 惠东县| 溆浦县| 老河口市| 永兴县| 光山县| 化德县| 营山县| 禹城市| 尉犁县| 延川县| 江孜县| 浮梁县| 珲春市| 天祝| 铜陵市| 南雄市| 大姚县| 民权县| 丽江市| 景洪市| 化德县| 鄂州市| 百色市| 赣州市| 东安县| 富蕴县|