MySQL5.6 支援Multi-Range Read索引最佳化

來源:互聯網
上載者:User

對於大表基於輔助索引)做範圍掃描時,會導致許多隨機IO,普通磁碟的瓶頸在於隨機IO效能上很差,在MySQL5.6裡,對這種情況進行了最佳化,一個新的名詞Multi-Range Read出現了,它的作用減少隨機IO,並且將隨機IO轉化為順序IO。

 
  1. mysql> desc t_06; 
  2. +-------+-------------+------+-----+---------+-------+ 
  3. | Field | Type        | Null | Key | Default | Extra | 
  4. +-------+-------------+------+-----+---------+-------+ 
  5. | id    | int(11)     | NO   | PRI | NULL    |       |  
  6. | c1    | varchar(30) | YES  |     | NULL    |       |  
  7. | i2    | int(11)     | YES  | MUL | NULL    |       |  
  8. +-------+-------------+------+-----+---------+-------+ 

當未開啟MBR時,EXPLAIN看到的是這樣,

650) this.width=650;" border="0" src="http://www.bkjia.com/uploads/allimg/131229/1U240O33-0.jpg" alt="" />

當開啟後,EXPLAIN看到的是這樣,

650) this.width=650;" border="0" src="http://www.bkjia.com/uploads/allimg/131229/1U2405623-1.jpg" alt="" />

MySQL5.6是預設開啟的

650) this.width=650;" border="0" src="http://www.bkjia.com/uploads/allimg/131229/1U2403D5-2.jpg" alt="" />

這是官方給的一個例子,

650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1U2401Y0-3.jpg" />

在未開啟MRR時,先過濾出key_part1在1000和2000之間的資料,然後在結果中再過濾出key_part2等於10000的行。

在開啟MRR時,在找出1000的同時再找出10000,查詢條件拆分為{1000,10000},{1001,10000}……{1999,10000}。

對比測試:

650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1U2406354-4.jpg" /> 650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1U240H58-5.jpg" />

參考手冊:

650) this.width=650;" border="0" alt="" src="http://www.bkjia.com/uploads/allimg/131229/1U2406317-6.jpg" />

 

本文出自 “賀春暘的技術專欄” 部落格,請務必保留此出處http://hcymysql.blog.51cto.com/5223301/1092003

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.