99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

什么是MySQL索引提示-創新互聯

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

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

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

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

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

index hint種類

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

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索引提示”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯-成都網站建設公司網站,小編將為大家輸出更多高質量的實用文章!

分享標題:什么是MySQL索引提示-創新互聯
標題路徑:http://www.yijiale78.com/article34/csocse.html

成都網站建設公司_創新互聯,為您提供企業建站、響應式網站網站設計公司微信公眾號、品牌網站制作動態網站

廣告

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

商城網站建設