LoginSignup
1
1

More than 5 years have passed since last update.

Oracle IN句の代わりに擬似テーブルを使ってみた

Posted at

IN句に40個くらいの条件を入れたら、7秒ほどかかったので、
擬似テーブルを使ったらどうなるんだろうかと思い、実験してみた。
Oracle 11gで検証。

SQL内でしか使わない使い捨ての擬似テーブル

SELECT *
FROM table
WHERE id IN (00001, 00002, 00003)

こんな風に書いていたSQLを
下記のように書き換えて実行してみる。

SELECT table1.* 
FROM table table1
     ,(
         SELECT 00001 AS id FROM dual
         UNION ALL
         SELECT 00002 AS id FROM dual
         UNION ALL
         SELECT 00003 AS id FROM dual
     ) table2
WHERE table1.id = table2.id

実行時間は11秒。。。
遅すぎるので結局大人しくIN句を使った

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1