Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Oracle / Oracle Server / May 2005

Tip: Looking for answers? Try searching our database.

Does IN perform a implicit distinct ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobde6@hotmail.com - 31 May 2005 11:57 GMT
Hi All

I was wondering if anybody knew if 'IN' performs a implicit distinct?
For instance say if i had the query below:

select stat from orders where account_id in (select distinct account_id
from accounts)

Do i need to perform a distinct lookup of the account_id ??? Is this
just a duplicate - which would require an additional sort?

I have constructed a benchmark with the same value repeated in the IN
caluse and I see no difference in response time / CPU time

Test 1
 select count(*) from accounts where account_id in ('15')

Test 2
 select count(*) from accounts where account_id in
('15','15','15','15','15')

Test 3
 select count(*) from accounts where account_id in
 ('15','15','15','15','15','15','15','15','15','15')

Test 4
 select count(*) from accounts where account_id in
 ('15','15','15','15','15','15','15','15','15','15',
  '15','15','15','15','15','15','15','15','15','15',

  '15','15','15','15','15','15','15','15','15','15',

  '15','15','15','15','15','15','15','15','15','15',

  '15','15','15','15','15','15','15','15','15','15')

Bob
sybrandb@yahoo.com - 31 May 2005 12:05 GMT
The IN operator refers to a *SET*. According to relational calculus, a
set never has duplicates!
So the distinct in your first statement is, by design, fully redundant.
In the past (pre 9i), the optimizer definitely wasn't smart enough to
notice the distinct was redundant, so it performed two sorts.

One would wish people would do something to learn relational concepts!

--
Sybrand Bakker,
Senior Oracle DBA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.