Classic MySQL limit query optimization

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags classic content data it is multiple multiple times mysql mysql database

The following article is mainly on the MySQL limit query optimization of the specific content, we all know that the MySQL database optimization is very important. The other most common and most desirable optimization is limit. The MySQL limit to paging has brought great convenience, but when the amount of data, limit the performance dropped sharply.

The same is to take 10 data

select * from yanxue8_visit limit 10000,10 select * from yanxue8_visit limit 0,10

It is not a quantitative level.

There are also many online optimization guidelines for the limit, which are all translated from the MySQL manual, although correct but impractical. Today found an article written on the limit optimization, very good.

The article is not directly use the limit, but first get the offset id and then directly use the limit size to get the data. According to his data, it is obviously better than using limit directly. Here I use the data in two cases to test. (Test environment win2033 + p4 dual-core (3GHZ) + 4G memory MySQLlimit query)

1, offset relatively small time

1.select * from yanxue8_visit limit 10,10

Running multiple times, the time remained between 0.0004-0.0005

Select * From yanxue8_visit Where vid> = (Select vid From yanxue8_visit Order By vid limit 10,1) limit 10

Running multiple times, the time remained between 0.0005-0.0006, mainly 0.0006

Conclusion: Offset offset smaller, the direct use of limit better. This is obviously the reason for the subquery.

2, offset big time

select * from yanxue8_visit limit 10000,10

Running multiple times, the time remained at 0.0187 or so

Select * From yanxue8_visit Where vid> = (Select vid From yanxue8_visit Order By vid limit 10000,1) limit 10

Running multiple times, the time remained at around 0.0061, only the former one-third. The larger the offset, the better the latter.

After the pay attention to correct their own limit statement, optimize MySQL

Recommended comments

MySQL optimization is very important. The other most common and most needed optimization is limit. The MySQL limit to paging has brought great convenience, but when the amount of data, limit the performance dropped sharply.

The above is related to the optimization of the introduction of MySQLlimit query, hope you can gain something.

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.