sql优化技巧
第一篇博客,就写下今天遇到的sql优化的问题吧。
not in效率很差,因为需要2表全表检索(单表情况),而且没有用到表索引,替代写法可以用外连接:
select a.* from A a
where a.id not in
(select b.id from B b)
替代:
select a.* frm A a
left join B b on a.id = b.id
where b.id is null
也可以not exists
select a.* from A a not exists (select b.* from B b where b.id = a.id)
另外,前几天面试被问到的:union和union all区别,union不含重复列,union效率差,当时我说union效率差时,面试官质疑我了下,不知道是唬我还是什么,我测试过应该是没错;聚集性索引和非聚集索引,http://kb.cnblogs.com/page/44125/;
最后,计划下最近需要学的东西吧,javaSE还是要继续温习下,其中io和多线程需要系统过一遍;linux的系统学习。
浙公网安备 33010602011771号