下面q段是抄?br />
Select * from T1 where x in ( select y from T2 )
执行的过E相当于:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
select * from t1 where exists ( select null from t2 where y = x )
执行的过E相当于:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
从我的角度来_in的方式比较直观,exists则有些绕Q而且in可以用于各种子查询,而exists好像只用于关联子查询Q其他子查询当然也可以用Q可惜没意义Q?br />
׃exists是用loop的方式,所以,循环的次数对于exists影响最大,所以,外表要记录数,内表无所谓了Q而in用的是hash joinQ所以内表如果小Q整个查询的范围都会很小Q如果内表很大,外表如果也很大就很慢了,q时候exists才真正的会快qin的方式?br />
下面q段q是抄的
not in 和not exists
如果查询语句使用了not in 那么内外表都q行全表扫描Q没有用到烦引;
而not extsts 的子查询依然能用到表上的索引?br />
所以无论那个表大,用not exists都比not in要快?/font>
也就是说Qin和exists需要具体情况具体分析,not in和not exists׃用分析了Q尽量用not exists好了?br />

]]>