1.select * from A where A.id in (select AId from B )
2.select * from A where A.id exits (select * from B where B.AId = A.id )
1的過程類似于:
Array B=select AId from B;
for(b:B){
select * from A where A.id = b;
}
走的是A的索引,in所以適合數(shù)據(jù)量A>B的情況
2的過程類似于:
Array A = select * from A;
for(a:A){
select * from B where B.AId = a.id
}
走的是B的索引,所以適合數(shù)據(jù)量B>A的情況
3.select * from A where A.id not in (select AId from B )
4.select * from A where A.id not exits (select * from B where B.AId = A.id )
3的效果類似于
Array B=select AId from B;
for(b:B){
select * from A where A.id != b;
}
!=是不走索引的,走的全文掃描
4的效果類似于
Array A = select * from A ;
for(a:A){
!(select * from B where B.AId = a.id)
}
還是走的B的索引
轉(zhuǎn)載自http://sunxiaqw.blog.163.com/blog/static/990654382013430105130443/