mysql order by 出現Using filesort的解決辦法

來源:互聯網
上載者:User

標籤:

http://blog.csdn.net/yangyu112654374/article/details/4251624

比如一條sql語句

select * from TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC; 

最佳化後是這樣: select A4,A1,A2 ... FROM TABLE1 where A1=1 and A2=2 and A3=3 order by A4 ASC; 並且給 A4,A1,A2,A3加索引,使用order by A4時,聯合索引要將A4放在首位。

SELECT的時候必須出現order by的欄位才行

2. 從上面可以看到聯合索引,也可以叫多列索引,形如 key (‘A1‘,‘A2‘,‘A3‘ ,‘A4‘)等的,排序的思路一般是,先按照A1來排序,A1相同,然後按照A2排序,以此類推,這樣對於(A1),(A1,A2),(A1,A2,A3)的索引都是有效,但是對於(A2,A3)這樣的索引就無效了。

 

mysql order by 出現Using filesort的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.