MySQL Tuning--using Temporary

Source: Internet
Author: User

The DBA sends a slow query problem on the line, and SQL is as follows (omitting some of the highlights for highlighting):
SELECT DISTINCT Article0_.id, etc. fields from Article_table article0_, hits_table articlehit1_ where article0_.id=articlehit1_. ID order by hits;


Explain result: time consuming 4.03S
unexpectedly, there will be a using temporary, order by only use a table, under normal circumstances will not appear with the aid of the table and then sort the case (this situation is that multiple tables are related to the sort field will be caused), The normal situation should be only after sorting the tables that have a relationship and then making the connection operation (for example, inner join in this example). index What is actually built, see the Type field can be seen, can refer to MySQL tuning----left JOIN

a serious look at the SQL statement, unexpectedly in the primary key ID added distinct, this is not wasted performance, try to modify the statement as:
Select Article0_.id, etc field from Article_table article0_, hits_table articlehit1_ where article0_.id=articlehit1_.id order b Y hits;




Explain result: time consuming 0.04S
unexpectedly because of a distinct modification, let MySQL think two table sort need to use temporary table, is really a wonderful problem. Distinct is very time-consuming and ready to be covered in the next blog post.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MySQL Tuning--using Temporary

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.