我们有一个主表,10000个记录,其中5000条记录为status=completed
,另有5000条记录status=incompleted
。使用NOT IN进行查询优化
应用程序维护的人有不同的种类...说users,visitors,admin
..
游客非常少(比如200个记录)......,当他们购买的东西在应用中appid
获取与更新的状态完成= 。
我们需要谁拥有status!=completed
我知道,直接的方法是不错的表现了游客的appid
..(下一个)
select appid
from application
where status != completed and appid in (select appid from visitors)
appid
也包含在游客和以及在应用..作为应用程序包含5000完成和5000未完成
NOT IN (select appid from application where status=completed)
也与IN (select appid from application where status=incompleted)
select v.appid
from visitors v
where v.appid not in (select appid from application where status = completed)
是我第二次查询给出了1倍的查询性能相同..
如果NOT IN
执行就像this..then是..
我下面写的语句。
for each v.appid in visitors{
do not select the v.appid if v.appid is in by firing the query as below.
select appid
from application
where appid = v.appid and status = completed
}
将第二个查询大火,我上面所说的过程...
,以提供更好的性能相同,与1日查询可以我下面写一个..
select v.appid
from visitors v
where v.appid not in (select appid
from application
where status = completed and appid = v.appid)
我如何编写第二个查询以便它与第一个查询执行相同的级别?
有什么理由不使用连接 – Sunny 2013-05-11 05:52:47
哪个RDBMS是这个吗? – 2013-05-11 07:47:09
@DavidAldridge oracle dbms – 2013-05-11 08:59:17