When the amount of data is relatively large, if limit paging query is performed, the efficiency of paging query will be lower as the query goes further.
Let's take a look at the time-consuming comparison of executing limit paging queries:
Through testing, we will see that the further you go, the lower the efficiency of paging query, which is the problem of paging query.
Because, when performing a paging query, if you execute limit 2000000,10
, you need
MySQL
to sort the first
2000010
Records, only 2000000 - 2000010
records are returned, other records are discarded, and the cost of query sorting is very high.
Optimization idea
:
In general pagination query, the performance can be better improved by creating a covering index, which can be optimized by adding a
subquery .
explain
select
*
from
tb_sku t , (
select
id
from
tb_sku
order by
id
limit
2000000
,
10
) a
where
t
.id
= a
.id
;