詳細(xì)出處參考:http://www.jb51.net/article/11123.htm 使用EXISTS(或NOT EXISTS)通常將提高查詢的效率,由于NOT IN子句將對子查詢中的表執(zhí)行了一個全表遍歷。 oracle在執(zhí)行IN子查詢過程中,先執(zhí)行子查詢結(jié)果放入臨時表再進(jìn)行主查詢; 而exists先運行主查詢,再執(zhí)行子查詢查到第一個匹配項 如:查詢 A表中沒有和B表或C表相連的數(shù)據(jù) select A.id,A.reads,A.addtime from A where A.person_id not in (select user_id from B ) or A.worksite_id not in (select id from C) order by A.addtime desc 程序執(zhí)行時間:40109.38毫秒 select A.id,A.reads,A.addtime from A where not exists (select id FROM B where B.user_id=A.person_id) or not exists (select id FROM C where C.id=A.worksite_id) order by Sendorder.addtime desc 程序執(zhí)行時間:8531.25毫秒 |
|