SQL-difference and performance of SQL statements that query statistical data volume when MySql executes paging

Source: Internet
Author: User
Now the development system involves querying by page. when doing this, I am thinking, whether or not the query SQL statement can be automatically encapsulated by parameters into the ability to count the data size of the query statement that is not queried by page. for example, the general practice is: 1. first query based on the concatenated SQL statement: select * fromecs_goodswheregoods_type1limit1000, 102. count again: selectcount (*) fromecs_goodswheregoods_type1 then we can get the paging-related data. now the logic is: 1... sqlmysql programmer data

Now the development system involves querying by page. when doing this, I am thinking, whether or not the query SQL statement can be automatically encapsulated by parameters into the ability to count the data size of the query statement that is not queried by page. for example, the general practice is:

1. first query based on the concatenated SQL statement: select * from ecs_goods where goods_type = 1 limit 1000, 10

2. count again: select count (*) from ecs_goods where goods_type = 1

Then we can get the paging data.

The logic is as follows:

1. the programmer writes an SQL statement with a query: select * from ecs_goods where goods_type = 1

2. the programmer passes in the paging information parameter and obtains the following information: limit, 10

3. The program automatically concatenates the following two steps: select count (*) from (select * from ecs_goods where goods_type = 1)

Will the query speed and performance vary greatly between the two methods? Why?

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.