What is faster?

Hi Gurus,
can you please suggest me what is right way?
1. to join three tables in one SELECT
or
2. to have three SELECT's
In reality first query return ID for second query and this will return also another ID for "real" third query.

All good points - however just to nitpick your IN vs EXISTS example, the optimizer will generally transform both queries into a semijoin using an index, if that will result in a lower cost:
SQL> @ind dept
                                                                                  Distinct
Index                        Unique? Type                  Status          Rows       keys Column name
PK_DEPT                      Y       NORMAL                VALID              4          4 DEPTNO
SQL> @ind emp
                                                                                  Distinct
Index                        Unique? Type                  Status          Rows       keys Column name
PK_EMP                       Y       NORMAL                VALID             14         14 EMPNO
SQL> SELECT dname, deptno
  2  FROM   dept d
  3  WHERE  d.deptno IN (SELECT e.deptno FROM emp e)
  4 
SQL> @xplan
Plan hash value: 1090737117
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT             |         |     3 |    48 |     6  (17)| 00:00:01 |
|   1 |  MERGE JOIN SEMI             |         |     3 |    48 |     6  (17)| 00:00:01 |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00:00:01 |
|*  4 |   SORT UNIQUE                |         |    14 |    42 |     4  (25)| 00:00:01 |
|   5 |    TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   4 - access("D"."DEPTNO"="E"."DEPTNO")
       filter("D"."DEPTNO"="E"."DEPTNO")
SQL> SELECT dname, deptno
  2  FROM   dept d
  3  WHERE  EXISTS
  4         ( SELECT e.deptno FROM emp e
  5           WHERE  d.deptno = e.deptno)
  6 
SQL> @xplan
Plan hash value: 1090737117
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT             |         |     3 |    48 |     6  (17)| 00:00:01 |
|   1 |  MERGE JOIN SEMI             |         |     3 |    48 |     6  (17)| 00:00:01 |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00:00:01 |
|*  4 |   SORT UNIQUE                |         |    14 |    42 |     4  (25)| 00:00:01 |
|   5 |    TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   4 - access("E"."DEPTNO"="D"."DEPTNO")
       filter("E"."DEPTNO"="D"."DEPTNO")
SQL> create index emp_deptno_ix on emp(deptno) compute statistics;
Index created.
SQL> SELECT dname, deptno
  2  FROM   dept d
  3  WHERE  d.deptno IN (SELECT e.deptno FROM emp e)
  4 
SQL> @xplan
Plan hash value: 151962099
| Id  | Operation          | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT   |               |     3 |    48 |     3   (0)| 00:00:01 |
|   1 |  NESTED LOOPS SEMI |               |     3 |    48 |     3   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| DEPT          |     4 |    52 |     3   (0)| 00:00:01 |
|*  3 |   INDEX RANGE SCAN | EMP_DEPTNO_IX |     9 |    27 |     0   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   3 - access("D"."DEPTNO"="E"."DEPTNO")I just mentioned this because "EXISTS is faster than IN" is often repeated around the forums when it is not necessarily true. Of course, I totally agree with the general point, that an SQL query can be written in many different ways and some are far less efficient than others (and cannot be automatically transformed into efficient ones by the optimizer).

Similar Messages

  • Memory Question "4x1 Gig or 2x2 Gig?" what is faster?

    Memory Question "*4x1 Gig or 2x2 Gig*?" what is faster?
    I'm still don't know if witch to choose?
    4 times 1 gigabyte Ram Memory is cheaper but if I choose for 2 times 2 GB Ram I can always beef it it later.
    And is my memory faster if I'm using 4 slots with 1 gig over 2 slot with 2 gig?
    I'm asking this question because I think using 4 times the memory bandwidth will be faster?
    http://www.janmaartendewit.com

    Hello Jan
    Welcome to Apple Discussions
    The iMac (Late 2009): Installing or replacing memory article and your User's Guide are pretty clear, they both say that +"You can use 2 GB or 4 GB RAM SO-DIMMs of 1066MHz DDR3 SDRAM in each slot."+ and not 1GB modules. > http://support.apple.com/kb/HT3918
    To upgrade your ram you will want at least 2 more 2 or 4GB modules and add that to the current 2 x 2GB of ram. > http://eshop.macsales.com/shop/memory/iMac/DDR321.527
    Dennis

  • What is faster thunderbolt or usb 3.0 gigabit ethernet

    What is faster a thunderbolt to gigabit ethernet adapter or a usb 3.0 gigabit ethernet adapter?
    Thanks

    Both Thunderbolt and USB 3.0 have bandwidths that exceed gigabit ethernet so based on theoretical numbers they should perform the same. However, different product manufacturers will write different drivers and use different hardware so unless you test specific products the question can't really be answered. Probably have to wait until magazines such as MacWorld or other Mac related websites test and compare devices.

  • What is faster, an iphone 6 or a samsung galaxy s6?

    what is faster,an iphone 6 or a samsung galaxy s6

    Hi there
    I’d be happy to help with your device question! As far as performance goes, these two devices are considered to be quite evenly matched, however in benchmark tests, the Samsung Galaxy S6 appears to outperform the iPhone 6. In normal day-to-day usage, you’d be hard pressed to be able to tell the two apart when it comes down to performance! I’d recommend visiting one of our AT&T company stores where you can test them out for yourself!
    I hope this helps!
    Charise

  • What is faster Me.Filter or Me.RecordSource

    I created a form that Search As You Type. When you type in a combo box, Access displays matching records. I use the On Change event with a private Sub. To find the records you can use the Form Filter or Form RecordSource property with a Sql Where Clause.
    Finding the records is compute intensive. In general, what is faster to use:
    Me.Filter or Me.RecordSource?
    Thanks

    See
    Good Design Generally - Filter or Change RecordSource?
    In short: it doesn't matter much but one or the other may be preferable depending on the circumstances.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • What is faster: DataReader or DataSet or something else?

    Hi,
    I need to read 250,000 records and show this information.
    I am using DataReader and it takes 8 seconds. I need to raise it to 0.8 seconds atleast.
    What is faster: DataReader or DataSet or something else?
    Thank's
    Alexei

    Is it an I/O issue?  Have you tried looking at
    some performance counters to see where the bottleneck might be?
    Is it a query issue?  How complex is the
    query?  Do you have proper indexes in place?
    Adam Machanic
    Pro SQL Server 2005, available now
    http://www..apress.com/book/bookDisplay.html?bID=457
    <[email protected]>
    wrote in message news:[email protected]..Hi,
    I
    am using the sql server on local
    machine.
    Thank's
    Alexei

  • What's faster???

    hello
    One way is to transit data from one table MSSQL to another one on ORACLE, like in LKM SQL to ORACLE.
    Second way is to unload data to file with BCP at the first and then load it to data base ORACLE with SQL-loader.
    What's faster???

    If you are dealing with larger volumes of data, it is almost certainly going to be using the BCP/External-Table/SQLLOADER option. If you are dealing with small and frequent movements, the overheads of process invocation with the latter might be unwarranted.
    It depends!
    Craig

  • Whats a faster internet connection joining one or create one.i have one ps3 i imac 2 ipads and one macbook pro?

    whats a faster internet connection joining one or create one.i have one ps3 one imac 2 ipads and one macbook pro?

    For the AirPort Extreme Base Station to provide Internet access to network clients, it would need to be configured for: 1) Connection Sharing = Share a public IP address, and 2) Wireless Mode = Create a wireless network.
    Although the option: Wireless Mode = Join a wireless network, exists for the Extreme, it really serves no purpose and should not be used.

  • What is "Fast Retry" of CodeType in Return Code

    What is "Fast Retry" of CodeType in Return Code.
    Thanks.

    Hi Torsten
    It seems very useful. Some updates will fail, because it is running, and it needs to be closed before update.
    Will it repeat until the exit code isn't "Fast Retry" or it has repeat time?
    Thanks

  • Anybody knows what is "FAST VIEW" used for?

    Dear all,
    A question about data extract settings, 'build fast views'? Can anybody tell what are 'fast views' and what they are used for?
    Thanks,
    gypsy

    Thanks Frank.
    Some more follow up questions:
    1.) I checked and it seems that the default configuration is that this optimization is disabled. We have lots of code in our application that aren't calling RowSet.reset upon acquiring the view link RowSet and are expecting it to be "fresh." So I think it is false by default. Is this correct?
    2.) Our performance problem isn't really caused by the new instances of RowSet that are being created. As the documentation itself says, the overhead introduced by new instances of RowSet aren't that big. Our problem is caused by the Contention being introduced by the ViewDefImpl.isViewLinkAccessorRetained(). And since all of our ViewObject impl classes are extending from one common framework class(which just extends ViewObjectImpl), we can just override the isViewLinkAccessorRetained at that level to just return the default value(false). This should eliminate the calls that are causing contention problems. Would you agree that this is an acceptable course of action?
    3.) Just out of curiosity, why is ADF implementing the Property checking this way anyway? Shouldn't the value of this property be loaded only during VO instance construction (or some other reasonably infrequent event) instead?

  • I need to work on my pix faster, what is faster to work off of - internal SSD or external thunderbolt drive?

    I have an issue deciding what I need to do.
    I have purchase a LACIE 30TB NAS with Thunderbolt 2.0 ... my internal SSD is 1TB in my new Mac Pro (2014)
    I dont know how photoshop works... if I open the file to work on PS located in the LACIE drive would it be as faster as opening it and modify it on my internal SSD ?

    To know you would need the benchmark the actual devices.  http://ssd.userbenchmark.com/

  • What is faster JDBC or SQLJ ?

    hi
    i am writing a java stored procedure in db2.
    i have to process nearly a million reocrds. For ech record i have to do atleast 15 inserts/updates to the database.
    what would be better to use JDBC or SQLJ(static sql) in terns of speed

    hi
    i am writing a java stored procedure in db2.
    i have to process nearly a million reocrds. For ech
    record i have to do atleast 15 inserts/updates to the
    database.
    what would be better to use JDBC or SQLJ(static sql)
    in terns of speedLike all good performance questions... it depends. If I were going to process 1 million records and do 15 million insert/updates with the results, I would look first at using the database vendors native utilities. It may be faster to read the million records with Java and write 15 million records into a flat file in the format expected by a native load utility. Then use the native load utility to do the insert/ updates. These load utilities can be 100's of times faster than anything that can be written in Java at this time.
    If you are set on using Java, then... it depends. When using JDBC you should use Batch update functionality, this can speed up insert/update activity by 10x+, if you do it correctly (making sure that you select the appropriate batch size). Prepared Statements provide the least external overhead because the database engine only needs to parse the SQL statement a single time. However you are providing less information to the database optimizer and this could result in worse performance for update processing. Insert activity will not be negatively, and should be positively effected by using a prepared statement because there is no query logic. I haven't written a Java DB2 stored procedure, but I am assuming that you have normal JDBC functionalty available to you.
    I'm not sure exactly what SQLJ does for you. It sounds like it is similar to a Prepared Statement (static vs. dynamic SQL). Perhaps others who have used SQLJ can add some of their knowledge.
    Once again, I would highly recommend looking at alternative utility processing as your first choice, some form of hybrid Java Stored procedure with a load Utility as a second choice and Java stored procedure only, as your last choice. Remember that volumes tend to increase so if this is an on going process you want to allow for 2 or 3 million records for the future.
    Joel

  • CASE or DECODE - what is faster?

    when i use them in select clause with varchar2 or number datatype? (Oracle 10.2 EE)
    regards

    Hi,
    This helped me in understanding the difference between case and decode
    Quoting from an expert amoungst experts Billy Verreynne. here is what he says:
    From what i know, in case of multiple condition checking, Case is simpler to write when compared to Decode. Also Decode can not be used in PL/SQL code where as CASE is possible.
    There is very little performance difference between CASE and DECODE on the same platform. One has to run 100's of 1000's of iterations to see a difference, and even then it is debatable of whether that difference is just due to the CASE vs DECODE.
    There seems to be a difference in performance between CASE and DECODE depending on the type of CPU. On some CPU architecture a DECODE will seem to be just slightly faster. On others, the CASE will seem to be slightly faster.
    The performance difference is so slight that it makes very little sense in using that as primary criteria for whether to use CASE or DECODE. So unless you're calling this statement from a very tight loop doing millions of iterations, the decision should rather be which one, CASE or DECODE, best suits the need.
    Wrong question really.. unless you writing a very tight loop doing 100's of 1000's of iterations using that type of conditional structure. And even then performance difference will not be that significant.
    The right question to ask is which one is more flexible and allows for the programmer that comes after you to read and understand and maintain your code. The CASE statement is in this regard, a lot better than a DECODE statement.
    Looking just at performance (which I suggest you do not do in isolation!!), I get mixed results using 10G Enterprise on different platforms (HP-UX vs SUN AMD) and operating systems (HP-UX vs Linux).
    On the former the DECODE is slightly faster. On the latter the CASE is slightly faster.
    Using the construct you've specified and doing a tight loop of a 100,000 iterations, the elapsed execution times are:
    HP-UX DECODE = 00:00:11.83
    HP-UX CASE = 00:00:12.32
    Linux/AMD DECODE =00:00:02.02
    Linux/AMD CASE = 00:00:01.84
    Obviosuly the CPU architecture plays a major role here. The AMD is considered as the best 64 CPU on the market. The HP-UX PARISC CPU (also 64bit), does not really compare raw performance wise. In addition this is a RISC CPU whereas the AMD CPU is I believe more CISC than RISC.
    Also interesting that the faster Sun AMD/Linux server I used for this benchmark is about 10% the price of the HP-UX server.. and about 5x faster ito raw speed as this benchmark showed. :-)
    An interesting exercise, but one with little real world value. Yes performance is important. But within PL/SQL, not to the level about debating whether a CASE or DECODE is faster. As I've mentioned, I believe the right question being one about readability and maintenance and not performance in this case.
    Hope this helps and all credit goes to the expert billy.
    Edited by: Kevin CK on Aug 5, 2010 4:07 PM
    Edited by: Kevin CK on Aug 5, 2010 4:08 PM

  • What is faster in terms of song shuffling? touch, iPhone, classic?

    I have a 2nd gen IPOD touch, will upgrading to an iphone 4 or the newest touch reduce lag between shuffling songs?
    Is the touch faster than the classic since the classic is hard drive based?

    I have never noticed any lag while my iPods (Classic and 2nd gen Touch) are on shuffle and I let the songs finish.
    However, if I try to move to the next song within seconds of the song starting, and keep doing that, then yes, there may be a delay. That's probably because the iPod wasn't expecting to be asked to find a new song so soon.
    What exactly are you doing when this lag occurs? Are you letting songs finish or do you keep skipping to the next track? How long is the delay? Some more information is required.

  • What is faster to search an alpha numeric primary key or number datatype

    hi all,
    I am looking for the answer to a question. What provides a faster and or efficient search for a primary key in any RDBMS is it alpha numeric or number? and why?I would appreciate you replies please.

    Several years ago an Oracle support analyst posted the results of a test for a single column PK with where he compared the results for using a number data type verse a character data type. The analyst results showed you needed more than 100K accesses to measure any significant difference where the number data type showed a small performance advantage. Note that Oracle stores the number data type internally as a form of scientific notation and library math is necessary to work with the numbers. Most of the claims for using a number instead of character go back to the days where native binary words were used as the key. The test only covered signle column keys.
    Use the data type that matches your natural business keys and call it a day. If you try to substitute an artificial numeric key you are likely to have to go through a business character value to locate the artificial key so any performance benefit you think you can get by using a numeric key will be imaginary due to increased overhead of maintaining multiple indexes.
    You can set up and run your own tests.
    HTH -- Mark D Powell --

Maybe you are looking for