SQL: which is better IN or OR

Hi,
I have a query which is in the format:
select * from (
select col1, col2, col3
from tab1, tab2, tab3
where tab1.col1='aa' AND tab2.col2='BBB' ...
AND (tab1.col1='AA' OR tab1.col='BB' OR tab1.col='CC'... OR tab1.col='NN')
ORDER BY tab1.col3 DESC )
WHERE ROWNUM <= 500
(Please ignore the correctness of the query since I have simplified it)
My question is:
What is the difference in the performace between using OR with respect to using something like:
AND (tab1.col1 IN ('AA' , 'BB', 'CC'... ,'NN'))
Can someone please explain the difference in performace between using IN over OR?
Thanks,
- M

Check out the predicate information for both methods:
SQL> explain plan for
  2  select *
  3  from   dual
  4  where  dummy IN ('A','B','C','X','Y','Z');
Predicate Information (identified by operation id):
   1 - filter("DUAL"."DUMMY"='A' OR "DUAL"."DUMMY"='B' OR
              "DUAL"."DUMMY"='C' OR "DUAL"."DUMMY"='X' OR "DUAL"."DUMMY"='Y' OR
              "DUAL"."DUMMY"='Z')
SQL> explain plan for
  2  select *
  3  from   dual
  4  where (dummy = 'A'
  5      or dummy = 'B'
  6      or dummy = 'C'
  7      or dummy = 'X'
  8      or dummy = 'Y'
  9      or dummy = 'Z'
10        )
11  ;
Predicate Information (identified by operation id):
   1 - filter("DUAL"."DUMMY"='A' OR "DUAL"."DUMMY"='B' OR
              "DUAL"."DUMMY"='C' OR "DUAL"."DUMMY"='X' OR "DUAL"."DUMMY"='Y' OR
              "DUAL"."DUMMY"='Z')I think the IN version is a lot less typing and easier to maintain.

Similar Messages

  • Which is better for performance Azure SQL Database or SQL Server in Azure VM?

    Hi,
    We are building an ASP.NET app that will be running on Microsoft Cloud which I think is the new name for Windows Azure. We're expecting this app to have many simultaneous users and want to make sure that we provide excellent performance to end users.
    Here are our main concerns/desires:
    Performance is paramount. Fast response times are very very important
    We want to have as little to do with platform maintenance as possible e.g. managing OS or SQL Server updates, etc.
    We are trying to use "out-of-the-box" standard features.
    With that said, which option would give us the best possible database performance: a SQL Server instance running in a VM on Azure or SQL Server Database as a fully managed service?
    Thanks, Sam

    hello,
    SQL Database using shared resources on the Microsft data centre. Microsoft balance the resource usage of SQL Database so that no one application continuously dominates any resource.You can try the 
    Premium Preview
    for Windows Azure SQL Database which offers better performance by guaranteeing a fixed amount of dedicated resources for a database.
    If you using SQL Server instance running in a VM, you control the operating system and database configuration. And the
    performance of the database depends on many factors such as the size of a virtual machine, and the configuration of the data disks.
    Reference:
    Choosing between SQL Server in Windows Azure VM & Windows Azure SQL Database
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • SQL Loader or UTL_FILE , Which is better ??

    Hello All,
    In my system I have to Download the data from a file each day in some table.
    The file is of fixed format. And the number of records (lines) in the file is not more than 1000 (say) each day.
    I would like to know for such scenario what will be better to use, SQL Loader or UTL_FILE package to read the file?
    DB - Oracle Database 10g on Linux platform.
    Thanks & Regards,

    Subject: Re: SQL Loader or UTL_FILE , Which is better ??
    Hey,
    My control file 'ATTENDANCE.ctl' is as follows
    load data
    infile 'C:\DATA\06012007.CAP'
    badfile 'C:\DATA\atncap.bad'
    append
    into table NIS.atncap
    COMP_CODE constant 'SP',
    TXN_SRNO sequence(max,1),
    TXN_DATE POSITION(05:12) date 'MM/DD/YYYY' ,
    TXN_ATDATE POSITION(05:16) date 'MM/DD/YYYY HH24:MI',
    TXN_EMPL POSITION(17:24) INTEGER EXTERNAL,
    TXN_TIME POSITION(13:16) ,
    CREATED_BY constant '---',
    CREATED_DT sysdate,
    MODIFIED_BY constant '---',
    MODIFIED_DT sysdate,
    TXN_FILE POSITION(05:12) INTEGER EXTERNAL,
    TXN_INOUT POSITION(26:26) INTEGER EXTERNAL
    and sample data from my file which is to be loaded is
    CC000601200707300025831201FF09D071
    CC000601200708330025836601FF09D17F
    CC000601200710260025830001FF09D271
    CC001201200718480025836201FF09D374
    CC000601200719100025836601FF09D47B
    which contains some flags, date, in/out times, employee code etc. and the positions of all the fields is fixed. The file is generated on daily basis with system date as the file name.
    i.e. above data is from file '06012007.CAP'. We can easily see the date field is at positions 05 to 12 in the file.
    So, for this purpose each time I have to update the control file for 'infile' parameter.
    Thats what I said in my second post.
    Message was edited by:
    Abhijit Deshmukh

  • Which is better for User Managed Hot backup - running in cron or oracle scheduler

    We are taking hot backup in our environment by using sql script of just begin backup, host copy and end backup
    Can we use this script to be put in cron for weekly two times or to use oracle scheduler .
    Which is better option and why?

    The answer to your question depens on your condition. Do you have more experienced Unix admin or DBA?
    From my point of view cron is better becuase all you need is SQL*Plus utility and shell script:
    export ORACLE_SID=...
    sqlplus <username>/<password> as sysdba <<EOF
    ALTER TABLESPACE .. BEGIN BACKUP;
    host copy ..
    ALTER TABLESPACE .. END BACKUP;
    EXIT
    EOF

  • Performance wise which is better NOT IN or NOT EXISTS

    Performance wise which is better NOT IN or NOT EXISTS.

    also that not exists is not equivalent to not in
    SQL> select * from dept where not exists (select * from emp where dept.deptno=comm);
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> select * from dept where deptno not in (select comm from emp);
    no rows selectedin most case, Oracle internally rewrite a NOT IN in a NOT EXISTS, because NOT EXISTS usually performs better.
    HTH
    Laurent

  • Subquery vs UNION, which is better for performance?

    I want to know which in better for performance using a subquery method or a UNION?
    Any information would be helpful and appreciated!

    Hi,
    It depends on the SQL statments and each case is different from an other one. Take a look at the oracle doc: "Designing and Tuning for Performance".
    Regards,
    CB

  • Which is better to use: BEx query or Web Application as an iView in portal?

    Hi gurus!
    Are there any experienced opinions, which is better - publish a BEx query in portal or publish a BEx Web Application in portal? Is it easier to alter the layout attributes etc. if I create a BEx Web Application first before publishing?
    What is the way of fixing for example filter item height if I publish BEx query in portal - is there a Web Application that it uses anyhow which I can fix? Or can I use in that case iView -properties in portal?
    Thankful for advice
    Sari

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Which is better??????

    which is better?Dam really confused which speaker to buy??
    i currently have a creative m2600.but am not getting enough performance or that feel while watching movies like avatar,step up 3 etc......so am planning to buy a 5.1.......not planning but i have decided to buy a 5.1....so..
    which is better? the 6160 or 6060 or 6100.
    which of these will provide me relly great exprience while playing games and most importantly while whatching hd movies and while listening to music.......
    and other than this what i have to ask is...what is this "db" in speakers. i mean while looking at a speaker specs we can see it..like 65db,85db,75db..etc........
    and when i compared specs of the three speakers i mentioned above i saw that the 6160 has low "db"........why is that?

    The specs is just a guide, you won't be able to tell the slight difference in db using just your ears. Besides, it is just a comparison between the level of a music to the level of background noise, it does not necessary mean which speaker sounds better. If possible, please make a trip to your local electronics store and try out the speakers system yourself.

  • Which is better, Photoshop or Corel?

    Which is better, Photoshop or Corel? I am finding the best one to use for my website [link removed]. Let me know your opinion. Tks all.

    Thank you! I am trying to find the best one for the site [Link removed].
    I used to use Corel before, but now, I am trying to use Photoshop.
    Tk you anyway
    [Removed link]
    Message was edited by: sinious

  • Which is better software for brochures and PDF forms ? Photoshop or InDesign ?

    Which is better software for brochures and PDF forms ? Photoshop or InDesign ? and why ?

    If you are going to be making a lot of brochures, with photos, you probably want both. Photoshop to edit the photos, and InDesign to assemble and layout images with text.

  • Which is better an android or apple

    Which is better getting an android smart phone or an Apple I Phone?

    As the poster Horses 547 said its a matter of personal preference. However I own and use both. Printing via air print is smooth and easy on an iphone. Printing on a android phone is iffy and tedious and you will have to find an app to print since there is no native app to do so. I purchased http://www.printhand.com which costs around $12 from the app store. but it is in my opinion the best printing app out there for android. I use it on my android tablet as well and its great. This company is the maker of the print app on iphones.
    The iphone is a little harder to put your own ringtone on the device. However very easy from the Itunes you put on your computer and hook into.
    Another thing an iphone does is if you use their cloud service or pay for a song it is available on all your ios devices. Iphone, ipad, or ipod or up to five computers registered through itunes on those computers.
    Google play music also can sync with all your android devices.
    Iphone don't have external Micro SD card slots, so the storage on the phone is all you have.
    Iphones use imessage which does not count against your text allotment  to another iphone or ipad user. it send regular text to non iphone users.
    Another thing is Face Time but I found a better program called oovoo at http://www.oovoo.com or in the Google Play Store for free.
    Iphones are paper thin but I have an android that has a larger view area and is also paper thin and light. Depending on the android phone it may have a removable battery, whereas iphones are sealed as are some new androids. I have found the sound for music better on my iphone, and videos are crystal clear. Again on some better androids the music and video is comparable .
    There is really not many differences but it up to the user.
    One last good thing is iphones are updated via Apple, no long waits for OS updates like is done with Android devices, and android devices on Verizon.

  • Which is better for doing animation? Flash 4, 5, MX, CS, or others?

    Which is better for doing animation? Flash 4, 5, MX, CS, or
    others?
    I am used to using brush function more conveniently in Flash
    4 than the other versions I ve tried. However, Flash 4 doesn't have
    pen tool.
    Free News Reader
    http://put.hk
    http://put.hk/reader/forums.macromedia.com/macromedia.flash.html

    1Evan2Wing3 wrote:
    > Which is better for doing animation? Flash 4, 5, MX, CS,
    or others?
    >
    > I am used to using brush function more conveniently in
    Flash 4 than the other versions I ve tried. However, Flash 4
    doesn't have pen tool.
    all pretty identical tho I would go with cs, just because I
    like the GUI much
    more than other versions...
    Best Regards
    Urami
    "Never play Leap-Frog with a Unicorn."
    <urami>
    If you want to mail me - DO NOT LAUGH AT MY ADDRESS
    </urami>

  • Which is better for bulk message scenario in sap xi RFC or Proxy

    which is better for bulk message scenario in ( RFC or Proxy ) ?
    Edited by: prabhatxi on Aug 6, 2010 4:44 PM

    Proxy will alwaays be better option in this case, as it is adapter less framework, and communication happens directly with XI central integration engine. So it is always fast communication and gives good performance.
    But still you should consider other factors, you may consider using RFC as well, as sometime we go for RFC/IDOC as this are the standard interfaces already available rather than creating structure...
    May be you can share more info on what type/volume data are you planning to send via XI?
    Hope this cleart your doubt..
    Divyesh

  • Which is better - Add a dimension or create more members in an existing

    Which is better - Add a dimension or create more members in an existing dimension?
    We are trying to figure out which can give us better performance in terms of calculations and retrieving reports - to add another dimension (entity/country) or add about 500-800 more members in an existing location/division dimension?
    Thank you!

    If you have BSO cube i would recommend to add in the same dimension where as ASO you can add members in a new dimension. Adding a new dimension is like creating a new cube you have to change each and every single calc scripts,report scripts,FR reports,Webforms and your rule files .... all the dependencies has to be changed manually . I think 500 members in the exsting BSO dimension will not impact the calc or retrieval times that much .

  • Which is better for servers, Apache or Tomcat?

    Which is better for servers, Apache or Tomcat?

    For some reason that link I gave you isn't working right now, but it was today, weird. I would get Tomcat simple because sun uses it in its examples and recommends it. Here's sun's link then, it's probably more useful anyway. http://java.sun.com/products/jsp/

Maybe you are looking for

  • Mail wont load or do anything!?!?!?!?!? :(

    Well i open up m mail app and it comes up with the rainbow mouse loader and does nothing. It does not even show me my current emails in my inbox.... i then go to the force quite app and it says " mail not responding " anyhelp? Will

  • Error messahe re fire wire

    when I plug my iPod in to my car charger, I get a error message words like " Can not connect using a fire wire connection, switch to a usb connection..." at the bottom is states "Push middle button to dismiss", What does this mean. Also when I push m

  • PL/SQL QUESTION

    Greetings, Can someone explain why the following is happening... I have the following function returning a pl/sql query. create or replace function "PROJECTFILTER" (igroup in varchar2, status in varchar2) return VARCHAR2 is myq varchar2(32767); inum

  • My music, apps, movies everything has disappeared from my itunes library!

    why have all my music, apps, movies, EVERYTHING but a few files all of a sudden disappeared from my itunes library, and how do I get it back?!  I "checked for possible downloads" and it said all my material had been downloaded already. 

  • LDAP: error code 49

    Hi, I am testing a single sign-on with spnego configuration. When I run diagtool spnego.conf, I always get this error. Error connecting to the LDAP server [EXCEPTION] javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSI