10000 レコードのメイン テーブルが 1 つあり、5000 レコードがstatus=completed
あり、別の 5000 レコードがありstatus=incompleted
ます。
アプリケーションは、さまざまなカテゴリの人々を維持しています...たとえばusers,visitors,admin
..
訪問者は非常に少ない (たとえば 200 レコード)...彼らが何かを購入するとappid
、アプリケーション内が status=completed で更新されます。
appid
私たちは持っている訪問者を必要としていますstatus!=completed
私は、直接的な方法が良いパフォーマンスであることを知っています..(1つ下)
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)
私の2番目のクエリは、1番目のクエリと同じパフォーマンスを提供します..
実行がこのようなものである場合NOT IN
..それは..
以下に声明を書いています。
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
}
2番目のクエリは、私が言及した上記の手順を起動します...
最初のクエリと同じようにパフォーマンスを向上させるために、以下のクエリを記述できます..
select v.appid
from visitors v
where v.appid not in (select appid
from application
where status = completed and appid = v.appid)
1 番目のクエリと同じレベルを実行するように 2 番目のクエリを作成するにはどうすればよいですか?