SQL optimization - limit optimization

1. Limit optimization

Optimization is done by covering indexes and subqueries.
insert image description here

select * from tb_sku limit 0,10;

insert image description here

select * from tb_sku limit 9000000,10;

It took 19.39s to execute this sql
insert image description here

Returning * must be returned to the table. When optimizing, you can only return the id, and you can cover the index.

select id from tb_sku order by id limit 9000000,10;

Time-consuming 11.47s
insert image description here

select * from tb_sku where id in(select id from tb_sku order by id limit 9000000,10);
select s.* from tb_sku s,(select id from tb_sku order by id limit 9000000,10) a where s.id =a.id;

insert image description here
Optimized the time of nearly 9s.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44860226/article/details/131868622