MySQL Tuning-Using Filesort

Source: Internet
Author: User
This problem occurs because MySQL can use only one index per query, and your SQL statement WHERE condition and order by conditions are not the same, the index is not built, then the ORDER by is not used to index, there is a using filesort problem.
The solution to this problem is to create a hybrid index that contains the WHERE and ORDER by conditions.

For example, the original SQL statement is:

SELECT * from the user U where u.id=100 order by u.update_time

And the index is idx_user_id (ID)
Now re-establish the index to Idx_user_id_update_time (id,update_time) and use the EXPLAIN command to see if key is using the new Idx_user_id_update_time index above, you can see The using file sort problem disappears, and if key is not using the new Idx_user_id_update_time index, you can use the Force index () method to enforce the index, at which point the using Filesort problem is resolved.

SELECT * from User U Force index (idx_user_id_update_time) where u.id=100 order by u.update_time


MySQL Tuning-Using Filesort

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.