Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Paging query mode of MySQL

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "the paging query mode of MySQL". In the daily operation, I believe that many people have doubts about the paging query mode of MySQL. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "MySQL paging query mode". Next, please follow the editor to study!

When limit is used for paging queries, the performance gets worse when flipping backward. The principle to solve this problem is to narrow the scanning range, as shown below:

Select * from user order by id desc limit 100000Bol 10

It takes 0.4 seconds

Select * from user order by id desc limit 1000000 million 10

It takes 5.2 seconds

First, filter out ID to narrow down the scope of the query, as follows:

Select * from user where id > (select id from user order by id desc limit 1000000, 1) order by id desc limit 0Jing 10

It takes 0.5 seconds.

If the query condition has only the primary key ID, write as follows:

Select id from user where id between 1000000 and 1000010 order by id desc

It takes 0.3 seconds

What if the above plan is still slow? We have to use cursors.

At this point, the study of "paging query mode of MySQL" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report