Preface Usually, a "paging" strategy is adopted for MySQL queries with large amounts of data. However, if the page is turned to a later position, the query will become very slow because MySQL will spend a lot of time scanning the data that needs to be discarded. Basic paging techniques Usually, in order to achieve efficient paging, you need to apply a combined index to the WHERE condition column and the sort column in the query. 1. Field sorting ORDER BY a ORDER BY a,b ORDER BY a, b, c ORDER BY a DESC, b DESC, c DESC 2. Filter and sort WHERE a = const ORDER BY b, c WHERE a = const AND b = const ORDER BY c WHERE a = const ORDER BY b, c WHERE a = const AND b > const ORDER BY b, c 3. The following query cannot use the above index ORDER BY a ASC, b DESC, c DESC // The sorting direction is inconsistent WHERE g = const ORDER BY b, c // Field g is not part of the index WHERE a = const ORDER BY c // Field b is not used WHERE a = const ORDER BY a, d // Field d is not part of the index Solve the problem of page turning for large amounts of data 1. Change the query of LIMIT M,N to LIMIT N Examples: mysql> SELECT <cols> FROM profiles INNER JOIN ( -> SELECT <primary key cols> FROM profiles -> WHERE x.sex='M' ORDER BY rating LIMIT 100000, 10 -> ) AS x USING(<primary key cols>); The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: A brief introduction to the simple use of CentOS7 firewall and open ports
>>: JS realizes the card dealing animation
In daily work, we sometimes run slow queries to r...
Table of contents 1. Install Docker 2. Write code...
Overview Backup is the basis of disaster recovery...
getElementById cannot get the object There is a s...
symptom I set a crontab task on a centos7 host, b...
By applying it, some public areas of the website c...
Table of contents Event Loop Browser environment ...
Table of contents After creating a container loca...
The notepad program is implemented using the thre...
1. Introduction I have taken over a project of th...
This article shares with you the installation and...
Table of contents npm download step (1) Import (2...
Vue bus mechanism (bus) In addition to using vuex...
Table of contents Why use gzip compression? nginx...
Table of contents Preface Enumerable properties I...