mysql优化-覆盖索引查询,join

1 原始sql:

SELECT a.* FROM event_data a WHERE a.receive_time >= '2018-03-28 00:00:00' AND a.receive_time <= '2018-03-28 23:59:59' ORDER BY a.receive_time DESC LIMIT 56280,15;

改为查询索引列(这里指的是主键,速度快很多)

mysql> SELECT a.pk_id -> FROM event_data a -> WHERE a.receive_time >= '2018-03-28 00:00:00' -> AND a.receive_time <= '2018-03-28 23:59:59' -> ORDER BY a.receive_time DESC -> LIMIT 56280,15;

 2:吧主键结果集跟原表left join

SELECT
a.*
FROM
(
SELECT
pk_id
FROM
event_data c
WHERE
c.receive_time >= '2018-03-28 00:00:00'
AND c.receive_time <= '2018-03-28 23:59:59'
ORDER BY
c.receive_time DESC
LIMIT 56280,
15
) b
LEFT JOIN event_data a ON a.pk_id = b.pk_id

优化完成

posted @ 2018-08-21 10:41  洞玄巅峰  阅读(230)  评论(0编辑  收藏  举报