数据库案例分析
来源:互联网 发布:linux就该这么学视频 编辑:程序博客网 时间:2024/05/22 17:04
一张mysql大数据表有几千万数据,但有一自增id字段,且为主键,要遍历此表的所有数据,写出有效的方法和sql(禁止使用limit n,m)。
案例分析:数据表 collect ( id, title ,info ,vtype) 就这4个字段,其中 title 用定长,info 用text, id 是逐渐,vtype是tinyint,vtype是索引。10万数据的效果。
select id,title from collect limit 1000,10; 基本上0.01秒就OK
select id,title from collect limit 90000,10; 8-9秒完成
select id from collect order by id limit 90000,10; 0.04秒就OK。
为什么?因为用了id主键做索引当然快。
改进方法:select id,title from collect where id>=(select id from collect order by id limit 90000,1) limit 10;
select id from collect where vtype=1 order by id limit 90000,10; 很慢,用了8-9秒!
vtype 做了索引了啊?怎么会慢呢?vtype做了索引是不错,你直接
select id from collect where vtype=1 limit 1000,10; 是很快的,基本上0.05秒,可是提高90倍,从9万开始,那就是0.05*90=4.5秒的速度了。
案例分析:数据表 collect ( id, title ,info ,vtype) 就这4个字段,其中 title 用定长,info 用text, id 是逐渐,vtype是tinyint,vtype是索引。10万数据的效果。
select id,title from collect limit 1000,10; 基本上0.01秒就OK
select id,title from collect limit 90000,10; 8-9秒完成
select id from collect order by id limit 90000,10; 0.04秒就OK。
为什么?因为用了id主键做索引当然快。
改进方法:select id,title from collect where id>=(select id from collect order by id limit 90000,1) limit 10;
select id from collect where vtype=1 order by id limit 90000,10; 很慢,用了8-9秒!
vtype 做了索引了啊?怎么会慢呢?vtype做了索引是不错,你直接
select id from collect where vtype=1 limit 1000,10; 是很快的,基本上0.05秒,可是提高90倍,从9万开始,那就是0.05*90=4.5秒的速度了。
阅读全文
0 0
- 数据库案例分析
- 几个数据库案例分析
- 数据库设计案例分析
- 数据库案例分析
- 数据库并发一致性案例分析
- 数据库并发一致性案例分析
- [推荐]数据库并发一致性案例分析
- 高级语言案例分析_QQ_数据库操作
- 又拍网数据库架构案例分析
- struts2.X心得2--第一个struts2案例分析以及整合c3p0连接数据库案例分析
- 案例分析
- 案例分析
- 案例分析
- asp.net案例分析-“通讯录”-2-数据库逆向建模
- 数据库的多表查询(详细案例分析)
- 使用Spring AOP实现MySQL数据库读写分离案例分析
- 使用Spring AOP实现MySQL数据库读写分离案例分析
- 使用Spring AOP实现MySQL数据库读写分离案例分析
- Pinterest 首位产品经理:爆发式增长背后的 5 大经验总结
- 面向对象的正式与非正式解释!
- C++中虚基类
- php缓存技术总结
- hadoop SequenceFile详解
- 数据库案例分析
- Elasticsearch搜索类型(query type)详解
- Networking (neutron) concepts
- python Oracle 连接
- android自定义普通对话框,输入框对话框
- HDU5925:Coconuts(二维坐标离散化 + DFS)
- Tensorflow测试Mnist手写数据集
- Gradle2.0用户指南翻译——第六章. 构建脚本基础
- OpenAL播放pcm或wav数据流-windows/ios/android(一)