For mysql to achieve optimal query performance, I changed the paging query method to cursor: {code ...} the above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented? I thought about changing the sorting order {code...}... To make mysql achieve the best query performance, I changed the paging query to the cursor query method:
select * from reply where reply_id > last_id limit 20 order by reply_id ASC;
The above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented?
I thought about changing the arrangement order.
select * from reply where reply_id < first_id limit 20 order by reply_id DESC;
In this way, we also need to add a parameter to the url. I want to keep the url route as ingress. I have thought about using javascript's history. back (), but it still feels unreliable. is there a better implementation method?
Reply content:
For mysql to achieve optimal query performance, I changed the paging query method to cursor query:
select * from reply where reply_id > last_id limit 20 order by reply_id ASC;
The above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented?
I thought about changing the arrangement order.
select * from reply where reply_id < first_id limit 20 order by reply_id DESC;
In this way, we also need to add a parameter to the url. I want to keep the url route as ingress. I have thought about using javascript's history. back (), but it still feels unreliable. is there a better implementation method?
In fact, this is a routing problem, not a MySQL query problem...
There are many methods... For example
-
Last_id distinguishes between positive and negative numbers
Www.example.com/reply/12345stands for the next page
Www.example.com/reply/-12345represents the previous page.
-
Redefine routing rules
Www.example.com/reply/next/12345 next page
Www.example.com/reply/previus/12345 Previous Page
Cursor is suitable for unlimited loading. We recommend that you use the traditional method for paging.
PS: the traditional method is still converted to cursor... Therefore, your statement "to achieve optimal query performance" is not accurate.
If you want to solve the problem simply, add twoIn this way, the next page on the PC side and more loading on the Mobile side can be implemented.