SQLite应用之路---SQL查询优化

SQLite应用之路---SQL查询优化,第1张

概述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)/ sqlite应用之路---SQL查询优化 temp1: 2499条数据
temp6: 969596条数据
//注意时间单位ms和s //其中temp1和temp2已经给eID加上索引
1.in和 exists@H_301_11@ //外表大于子表的时候,使用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@H_301_11@ //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@H_301_11@ //在不考虑重复数据的时候,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@H_301_11@ //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 总结

以上是内存溢出为你收集整理的SQLite应用之路---SQL查询优化全部内容,希望文章能够帮你解决SQLite应用之路---SQL查询优化所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/1174564.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存