sqlite索引优化⽅法
本⽂摘⾃:速度测试结果:
1) select count(*) from t1,t3 where t1.word2=t3.word2; 很慢(t3.word2上没有索引)
2) select count(*) from t3,t1 where t1.word2=t3.word2; 很慢(t1.word2上没有独⽴索引)
3) select count(*) from t1,t2 where t1.word2=t2.word2;很快(t2.word2上有索引)
4) select count(*) from t2,t1 where t1.word2=t2.word2; 很慢(t1.word2上没有独⽴索引)
5) select count(*) from t1,t2 where t1.num=t2.num;很快(t2.num上有索引)
6) select count(*) from t2,t1 where t1.num=t2.num; 很快(t1的复合索引中,第⼀个列是num)
7) select count(*) from t1,t3 where t1.num=t3.num; 很慢(t3.num上没有索引)
8) select count(*) from t3,t1 where t1.num=t3.num; 很快(t1的复合索引中,第⼀个列是num) 结论:
1、索引可以⼤⼤加快查询速度
2、当有交叉查询时,from a,b两个表,取决于b表是否有索引
3、当b上的索引不是独⽴索引时,查询速度取决于⾮独⽴索引的第⼀个字段