The optimization of paging idea in MySQL query

Source: Internet
Author: User

It seems that few people are talking about paging, are we all addicted to limit m,n?

In the case of indexing, limit m,n speed is sufficient, but when searching for complex conditions,

where somthing ORDER by Somefield+somefield

MySQL searches the database for "all" qualifying records, and then takes out the M,n record.

If you have hundreds of thousands of data, and the user searches for some very popular words,

Then read the last few pages in turn wonderment ... MySQL should be very solemn and stirring operation of the hard drive.

So, you can try to let MySQL also store pagination, of course, to program with.

(Here is just an idea, welcome to discuss it together)

ASP paging: In the ASP system has a Recordset object to achieve paging, but a large number of data in memory, and do not know when the expiration (please ASP Master

Pointing).

SQL database paging: Using stored procedures + cursor paging, the implementation of the principle is not very clear, imagine if you use a query to get the desired results, or

ID sets that require subsequent pages to read the relevant records according to the IDs in the results. This allows for a small space to keep all IDs of this query. (Query knot in SQL

Do not know how to clear expired rubbish?

This allows MySQL to simulate a storage paging mechanism:

1. Select id from $table where $condition order by $field limit $max _pages* $count;

Query for IDs that match the criteria.

Limit the number of records that meet the maximum criteria, or you can not add them.

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.