SQLite应用之路---SQL查询优化
2013-01-30 14:12
295 查看
SQLite应用之路---SQL查询优化
temp1: 2499条数据temp6: 969596条数据
//注意时间单位ms和s
//其中temp1和temp2已经给eid加上索引
1.in和 exists
//外表大于子表的时候,使用in//外表小于字表的时候,使用exists
select * from temp1 where eid in (select eid from temp6)//1.92s
select * from temp1 where exists (select eid from temp6 where eid = temp1.eid)//66.48ms
select * from temp6 where eid in (select eid from temp1)//98.25ms
select * from temp6 where exists (select eid from temp1 where eid = temp6.eid)//2.40s
2.limit
//offset 越大,执行时间越长。select * from temp6 limit 900000,100//1.25s
select * from temp6 limit 1,100//7.12ms
//下面两句并没有网上说的效果
select * from temp6 where eid >= (select eid from temp6 order by eid limit 800000,1) limit 100//515.14ms
select * from temp6 limit 800000,100//474.13ms
3.union 和 union all
//在不考虑重复数据的时候,union all 比union效率高。//union all 两张表的时候,应该将大表放在左边
select * from temp6 union select * from temp1//187.17s
select * from temp1 union select * from temp6//190.30s
select * from temp6 union all select * from temp1//8.39s
select * from temp1 union all select * from temp6//42.03s
4.join
//join两张表的时候,应该把小表放在左边select * from temp1 a join temp6 b on a.eid = b.eid//54.21ms
select * from temp6 a join temp1 b on a.eid = b.eid//1.12s
相关文章推荐
- .Net+SQL Server企业应用性能优化笔记3——SQL查询语句
- SQL 函数的应用及比较对于海量数据查询优化
- .Net+SQL Server企业应用性能优化笔记3——SQL查询语句
- SQL大数据量查询的优化
- 优化SQL查询:如何写出高性能SQL语句
- SQL优化:使用查询提示
- SQL联合查询优化 用union all来代替union
- SQLite查询优化性能要点
- MySQL优化sql语句查询常用的30种方法
- SQL海量数据库的查询优化及分页算法方案1
- SQL查询优化——数据结构设计
- 应用索引技术优化SQL 语句(Part 1)
- SQL查询语句优化
- 应用系统SQL优化
- 帮盖尔优化SQL-----子查询优化的经典案例
- sql语句查询,多字段like模糊查询优化
- 浅谈MySQL中优化sql语句查询常用的30种方法
- SQL查询优化
- sql server查询时候注意的基本优化常识
- 包含IN子查询的SQL语句的优化