In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is the method of SQL optimizing limit pagination". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The problem with Limit and OFFSET is actually the problem with OFFSET, which causes MySQL to scan a large number of unwanted lines and then throw them away. If you use bookmarks, you can record the location of the previously fetched data. Then next time, you can start the scan directly from the recorded location.
Let's look at a case study:
Mysql > select id,product_id from product order by id desc limit 20 +-+-+ | id | product_id | +-+- -- + | 71986 | 63308c71b16642a4bfb75cbe1049188b | | 71985 | bb8eba635b6a4726b4172143fb1c1d04 | | 71984 | 273243e1c9c64ee39351ea01a2489fa6 | | 71983 | 83f253b3ecde47eebe6a6397dc0d319e | | 71982 | 3c9780c86d1f4f24b95c9a08b4839c99 | | 71981 | 183b197924434de0a47d1786773cb66f | | 71980 | aff3b1385ee74893a3729664991d8e86 | | 71979 | c662a0e5c4d64339a5a68b99268840e1 | | 71978 | fe905e3dbdd2421c8e5ca47cd47232a4 | | 71977 | 9a44f05fde72425fa4498b091d27fd58 | | 71976 | c31afbd9c4ac46ffac34b2a14a49fb9f | | 71975 | 62056557531143e18bc813c0c930dc96 | | 71974 | 4ea1f0c978ca4441a232f563ba7181ee | | 71973 | 413317481ccf449394ded39b53a0f5cf | 71972 | 493c6da548394bdc871d058bc93a9b93 | 71971 | 98fafa3c690243998b18da8a9f165297 | | 71970 | 2e299b3ad38d4ce48bd1481799cb11a2 | | 71969 | 7f176c93d9ac42659b40a40f4fbea937 | | 71968 | d87671838a3246ddb393a336b8806905 | | 71967 | 301e3b9cb8ab40d588547a9b7f8fdaba | +-+-+
In reverse id order, the first page takes 20 lines, and the id ranges from 71967 to 71986.
Next page:
Mysql > select id,product_id from product where id < 71967 order by id desc limit 20 +-+-+ | id | product_id | +-+- -- + | 71966 | fec841328f76466098e0f7ff71ad2e64 | | 71965 | 91383bdf53f64c0c957f00f5e894ee08 | | 71964 | 0fe1f36aecc64e59b1f833e2a809b1d9 | | 71963 | 583ccc4dd2bc48889b672c700ff723df | | 71962 | 2d7417d85f7d4bc5a403be95d42c66c2 | | 71961 | f46e02c1abc046ffba6a893a0af32211 | | 71956 | 1acd9bf330d24cfd90005cc2ade28f8d | | 71959 | cea963ee97814bc09b657c0453b0cb55 | | 71958 | 700caf0dc6c745198d141c8006f87ee3 | | 71957 | 2239be33ebd2485ea6209b5186456531 | | 71956 | 30a4095734074612ad0a0fb32bdab1e4 | | 71955 | d9071a755a994f2eae11c9fb17e8071a | | 71954 | 4d0453c47af347078bc6bc2b5942061c | | 71953 | dda45cced0844fd992194cbaa334e420 | 71952 | 6e65d866889e4b15abe272f1e814ecc2 | 71951 | 4b22cdbb1f34448494251fd4f3eb6425 | | 71950 | 38f5d0cac07a4dc5a33ca62609a6debd | | 71949 | faa53f03f4714c9bb0991eb6b18ed7d9 | | 71948 | c5719ee4fcad48d0a6bfc8f28b415f1e | | 71947 | c6beaaa94829465ab1f9b6e0187d2721 | +-+-+
This ensures that each paging query is efficient, but there are certain conditions for using such a query, such as:
1. There must be a primary key and it is monotonously increasing.
2. If the query statement has group by grouping, then this method cannot be used.
This is the end of the content of "what is the method of SQL optimizing limit pagination". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.