Mysql 索引最佳化 - 2

來源:互聯網
上載者:User

標籤:form   常量   查詢   bsp   大資料   group   資料   大數   增加   

永遠小表驅動大表(小資料驅動大資料)

in exists區別,SELECT * FROM A WHERE A.id in (SELECT id FORM B) 若A表資料大於B表資料用inSELECT * FROM A WHERE exists (SELECT 1 FORM B WEHRE B.id=A.id) 若A表資料小於B表資料用exists

 

ORDER BY使用索引

Mysql 兩種排序方式: 檔案排序,掃描有序索引排序 

MYSQL 能為排序和查詢使用相同索引

 

如何提高Order By的速度

Select 欄位不要用Select *

增加sort_buffer_size參數

增加max_length_for_sort_data

 

ORDER BY 滿足2個情況,會使用Index方式排序

  ORDER BY 使用索引最左前列 同升同降

      WHERE字句和Order by字句滿足索引最左前列  如果帶頭是個常量,就不會

 

KEY a_b_c

滿足下面情況產生Filesort

  ORDER BY a ASC, b DESC, c DESC 排序不一致,

  WHERE g = const ORDER BY b,c 丟失最左前列

  WHERE a = const ORDER BY c 丟失中間b索引

  WHERE a= const ORDER BY a,d排序不是索引的一部分

  WHERE a in (...) ORDER BY b,c最左列不是常量

 

GROUP BY 和  ORDER BY 最佳化相同,不同的是先排序後分組

 

Mysql 索引最佳化 - 2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.