As a followup to this two questions and its answers Question 1 and Question 2.
What gives better performance on Oracle using operator in
, or
or union
? I think on a table with >1 mio rows with 10-500 rows per distinct value of y.
select * from table where y in (1,2,3)
or
select * from table where (y = 1 or y = 2 or y = 3)
or
select * from table where y = 1
union
select * from table where y = 2
union
select * from table where y = 3
How is performance influenced if I add a and x = 1
? Column x is indexed as well and has same selectivity.
Summary: There is no best practise or advise to use one operator more over the others. In best case all 3 statements have same performance metrics. But it can be that one statement is better than the others.
There are some threads out there that discuss performance measure of sql statements on oracle:
- http://forums.oracle.com/forums/thread.jspa?threadID=501834
- http://asktom.oracle.com/tkyte/runstats.html
- http://stackoverflow.com/questions/1312663/how-to-measure-performance-of-query-in-oracle
The tools you have to deal with are execution plans and tracing tools to obtain best performance.