内容简介:开发同学按照传达的精神使用了上次说的大表翻页优化的方式在做翻页查询了。执行时间97秒。执行查看表总数都执行了
开发同学按照传达的精神使用了上次说的大表翻页优化的方式在做翻页查询了。执行时间97秒。
select a2.id,a2.keyword,a2.url from (select id from table_name order by id asc limit 73575000, 5000) a1, table_name a2 where a1.id=a2.id
select count(*) from table_name;
执行查看表总数都执行了 70292.60ms
,总行数是 118345950
行。
对于这种表,做大表翻页优化,也已经无效了。那应该怎么弄呢?
我们先不去纠结历史原因,为什么没有分表。着眼解决当前的问题。
问下具体开发的同学,是在全表扫描这个表是否命中一些违禁词。这样就好办了。我们只需要“ 分段扫描就行了呀 ”
select id from table_name where id>73575000 order by id asc limit 0, 5000
执行时间 19.63ms
select a2.id,a2.keyword,a2.url from (select id from table_name where id>73575000 order by id asc limit 0, 5000) a1, table_name a2 where a1.id=a2.id
执行时间 26.35ms
,又可以愉快的玩耍了。
总结
为什么可以这样写呢,因为这次是循环扫描,本次扫描就知道下次查询的起始 id。不会跳着访问。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- Mybatis关联查询(嵌套查询)
- MySQL高级查询---连接查询实例
- Oracle子查询相关内容(包含TOP-N查询和分页查询)
- Laravel Query Builder 复杂查询案例:子查询实现分区查询 partition by
- 打造出色查询:如何优化SQL查询?
- SQL优化-慢查询+explain查询
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Sovereign Individual
James Dale Davidson、William Rees-Mogg / Free Press / 1999-08-26 / USD 16.00
Two renowned investment advisors and authors of the bestseller The Great Reckoning bring to light both currents of disaster and the potential for prosperity and renewal in the face of radical changes ......一起来看看 《The Sovereign Individual》 这本书的介绍吧!