Record the downtime caused by a subquery

Source: Internet
Author: User

At a.m. on July 22, May 10, a text message was sent to the police. The XXX Business Database went down and was busy with various problems, so it was only possible to troubleshoot it at night.


Let's take a look at the alarm information first,

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/224P5CP-0.jpg "title =" 1.jpg"/>

From onwards, the SWAP partition of the server will trigger an alarm, and then the insufficient memory will trigger an alarm, and then the memory will be exhausted and HANG will die, causing the machine to crash.


I analyzed the slow log. As a result, a statistical SQL statement directly killed the server.


This must have been performed manually. It was executed by logging on to SQLYOG from stepping stone 98.149,

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/224P5O45-1.jpg "title =" 2.jpg"/>

It takes 170 seconds, and it is still running on the master database and a machine with services, resulting in Table lock. Other processes keep waiting, and the accumulation increases, directly run the server.


In the evening, I executed this SQL statement again on the slave database, and it took 11 minutes and 26 seconds to slow down as the table grows ),........................

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/224P5K43-2.jpg "title =" 3.jpg"/>


The performance of MySQL5.1 and MySQL5.5 sub-queries is quite poor. As a spam fighter, you must use the table connection method to optimize this SQL statement unless MySQL5.6 is just launched this year.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/224P5N00-3.jpg "title =" subquery .jpg "/>

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/224P5G21-4.jpg "title =" 4.jpg"/>

It takes only 0.01 seconds to get the result.


Therefore, I would like to remind you that such statistical SQL statements are complex and never run on the master database. The current performance of subqueries is poor.


Note: The image size after BKJIA's new version is small. If you want to see a large image, download the compressed file in the attachment .)



This article is from the "hechun's technical column" blog, please be sure to keep this source http://hcymysql.blog.51cto.com/5223301/1197663

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.