Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: IN or Exists --- performance issue
Munish,
You are right, as a *general rule of thumb* EXISTS is *usually* faster than IN..
There can however be problems when an EXISTS is used to manipulate or select data from a very large table, where the row exists in a far smaller table, as it will read every row in the large table, and then scan the smaller table for corresponding rows.. Is this the case with you?
You have a few options:
HTH Mark
Mark Leith | T: +44 (0)1905 330 281 Sales & Marketing | F: +44 (0)870 127 5283 Cool Tools UK Ltd | E: mark_at_cool-tools.co.uk =================================================== http://www.cool-tools.co.uk Maximising throughput & performance
-----Original Message-----
Sent: 03 June 2003 12:00
To: Multiple recipients of list ORACLE-L
Hi Listers
I have a unique performance problem. As a general rule by oracle while
writing SQL scripts EXISTS should be used in place of IN.
I'm having 2 sql for comparison using IN and EXISTS operators.
With IN operator
SELECT /*+ PUSH_SUBQ USE_NL (a) INDEX (a) */
COUNT(1)
FROM mam_assets a
ALWAYS_SEMI_JOIN
WHERE 1 = 1
AND a.is_current_version = 1
AND a."ID" IN (SELECT dmv3.asset_id
FROM mam_asset_attr_domain_values dmv3
WHERE dmv3.domain_value_id = 71
AND dmv3.asset_attribute_xid = 3
AND dmv3.domain_xid = 7)
With Exists Operator
SELECT /*+ PUSH_SUBQ USE_NL (a) INDEX (a) */
COUNT(1)
FROM mam_assets a
WHERE 1 = 1
AND a.is_current_version = 1
AND EXISTS (SELECT dmv3.asset_id
FROM mam_asset_attr_domain_values dmv3
WHERE a."ID" = dmv3.asset_id
AND dmv3.domain_value_id = 71 AND dmv3.asset_attribute_xid = 3 AND dmv3.domain_xid = 7)
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.484 / Virus Database: 282 - Release Date: 27/05/2003Received on Tue Jun 03 2003 - 06:59:40 CDT
--
Please see the official ORACLE-L FAQ: http://www.orafaq.net
--
Author: Mark Leith INET: mark_at_cool-tools.co.uk Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).