How can we say if Join better than using Sub Queries ??

Hi all,
I am trying to understand the rationale behind "Is _Inner Join_ better than using _Sub Query_ ?" for this scenario ...
I have these tables --
Table1 { *t1_Col_1* (PrimaryKey), t1_Col_2, t1_Col_3, t1_Col_4 }
-- Number of rows = ~4Million , t1_Col_3 has say 60% entries non-zero -----> (Condition 4)
Table2 { *t2_Col_1* (PK), t2_Col_2, t2_Col_3 }
-- Number of rows = ~150Million, t2_Col_2 maps to t1_Col_1 -----> (Condition 1). This means for every distinct value of t1_Col_1 (its PK) we'll have multiple rows in Table2.
Table3 { *t3_Col_1* (PK), t3_Col_2, t3_Col_3 }
-- Number of rows = ~50K, t3_Col_1 maps to t1_Col_2 -----> (Condition 2)
Table4 { *t4_Col_1* (PK), t4_Col_2, t4_Col_3 }
-- Number of rows = ~1K, t4_Col_2 maps to t3_Col_2 -----> (Condition 3)
Now here are the 2 queries: -
Query using direct join --
SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
FROM Table1, Table2, Table3, Table4
WHERE t1_Col_1=t2_Col_2 -- Condition 1
AND t1_Col_2=t3_Col_1 -- Condition 2
AND t3_Col_2=t4_Col_1 -- Condition 3
AND t1_Col_3 != 0
Query using SubQuery --
SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
FROM Table2,
(SELECT t1_Col_1, t3_Col_1, t4_Col_2
FROM Table1,Table3, Table4
WHERE
AND t1_Col_2=t3_Col_1 -- Condition 2
AND t3_Col_2=t4_Col_1 -- Condition 3
AND t1_Col_3!= 0
WHERE t1_Col_1=t2_Col_2 -- Condition 1
Now the golden question is - How can I document with evidence that Type-1 is better than Type-2 or the other way ? I think the 3 things in comparison are: -
- Number of rows accessed (Type-1 better ?)
- Memory/Bytes used (Again Type-1 better ?)
- Cost ( ?? )
(PS - testing on both MySQL, Oracle10g)
Thanks,
A

So, is it right to conclude that Optimizer uses the optimal path and then processes the query resulting in nearly the same query execution time ?If the optimizer transforms two queries so that they end up the same, then they will run in the same time. Of course, sometimes it cannot do so because of the the way the data is defined (nulls are often a factor; constraints can help it) or the way the query is written, and sometimes it misses a possible optimization due to inaccurate statistics or other information not available to it, or limitations of the optimizer itself.
Is this the right place to ask for MySQL optimization ?Probably not.

Similar Messages

  • Have loaded lion and now cant access office for mac or apple works as it says it does not support power pc applications, how can I acces them or better still reinstate them please

    Have loaded lion and now can't access office for mac or apple works as it says it does not support power pc applications, how can I acces them or better still reinstate them please?

    MS-Office for Mac versions 2004 and older do not run in Lion since these are PPC-apps for which Apple has dropped support.
    Free alternatives to open Word and Excel files:
    NeoOffice http://www.neooffice.org/neojava/en/index.php
    OpenOffice http://www.openoffice.org/
    Or get the 2011 MS-Office

  • How can i make the sound louder than it already is?

    How can i make this laptop louder than it already is? Is the sound quality of this mode typically this low?

    Hi,
    Are you talking about a home theater which is connected to you laptop or the laptop istelf ? If the laptop itself then what is it ? To help us answer question quicker, please read this:
       http://h30434.www3.hp.com/t5/First-Time-Here-Learn​-How-to/Welcome-Get-started-here/td-p/699035
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How Can We Tune the Joins with "OR" Caluse ?

    Hi
    We've identified one Query in one of Our PL/SQL Stored Procedure which is taking huge time to fetch the records. I have simulated the problem as shown below. The problem Is, How can i tune the Jions with "OR" Clause. i have tried replacing them with Exists Caluse, But the Performance was not much was expected.
    CREATE TABLE TEST
    (ID NUMBER VDATE DATE );
    BEGIN
      FOR i IN 1 .. 100000 LOOP
        INSERT INTO TEST
        VALUES
          (i, TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2452641, 2452641 + 364)), 'J'));
        IF MOD(i, 1000) = 0 THEN
          COMMIT;
        END IF;
      END LOOP;
    END;
    CREATE TABLE RTEST1 ( ID NUMBER, VMONTH NUMBER );
    INSERT INTO RTEST1
    SELECT ID, TO_NUMBER(TO_CHAR(VDATE,'MM'))
    FROM TEST ;
    CREATE TABLE RTEST2 ( ID NUMBER, VMONTH NUMBER );
    INSERT INTO RTEST2
    SELECT ID, TO_NUMBER(TO_CHAR(VDATE,'MM'))
    FROM TEST;
    CREATE INDEX RTEST1_IDX2 ON RTEST1(VMONTH)
    CREATE INDEX RTEST2_IDX1 ON RTEST2(VMONTH)
    ALTER TABLE RTEST1 ADD CONSTRAINT RTEST1_PK  PRIMARY KEY (ID)
    ALTER TABLE RTEST2 ADD CONSTRAINT RTEST2_PK  PRIMARY KEY (ID)
    SELECT A.ID, B.VMONTH
    FROM RTEST1 A , RTEST2 B
    WHERE A.ID = B.ID  
    AND ( (A.ID = B.VMONTH) OR ( B.ID = A.VMONTH ) )  
    BEGIN
    DBMS_STATS.gather_table_stats(ownname => 'PHASE30DEV',tabname => 'RTEST1');  
    DBMS_STATS.gather_table_stats(ownname => 'PHASE30DEV',tabname => 'RTEST2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST1_IDX1');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST2_IDX2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST1_IDX2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST2_IDX1');
    END; Pls suggest !!!!!!! How can I tune the Joins with "OR" Clause.
    Regards
    RJ

    I don't like it, but you could use a hint:
    SQL>r
      1  SELECT A.ID, B.VMONTH
      2  FROM RTEST1 A , RTEST2 B
      3  WHERE A.ID = B.ID
      4* AND ( (A.ID = B.VMONTH) OR ( B.ID = A.VMONTH ) )
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=94 Card=2 Bytes=28)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'RTEST2' (Cost=94 Card=1 Bytes=7)
       2    1     NESTED LOOPS (Cost=94 Card=2 Bytes=28)
       3    2       TABLE ACCESS (FULL) OF 'RTEST1' (Cost=20 Card=100000 Bytes=700000)
       4    2       BITMAP CONVERSION (TO ROWIDS)
       5    4         BITMAP AND
       6    5           BITMAP CONVERSION (FROM ROWIDS)
       7    6             INDEX (RANGE SCAN) OF 'RTEST2_PK' (UNIQUE)
       8    5           BITMAP OR
       9    8             BITMAP CONVERSION (FROM ROWIDS)
      10    9               INDEX (RANGE SCAN) OF 'RTEST2_IDX1' (NON-UNIQUE)
      11    8             BITMAP CONVERSION (FROM ROWIDS)
      12   11               INDEX (RANGE SCAN) OF 'RTEST2_PK' (UNIQUE)
    Statistics
              0  recursive calls
              0  db block gets
         300332  consistent gets
              0  physical reads
              0  redo size
            252  bytes sent via SQL*Net to client
            235  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed
    SQL>SELECT /*+ ordered use_hash(b) */ A.ID, B.VMONTH
      2    FROM RTEST1 A, RTEST2 B
      3   WHERE A.ID = B.ID  AND(A.ID = B.VMONTH OR B.ID = A.VMONTH)
      4  ;
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=175 Card=2 Bytes=28)
       1    0   HASH JOIN (Cost=175 Card=2 Bytes=28)
       2    1     TABLE ACCESS (FULL) OF 'RTEST1' (Cost=20 Card=100000 Bytes=700000)
       3    1     TABLE ACCESS (FULL) OF 'RTEST2' (Cost=20 Card=100000 Bytes=700000)
    Statistics
              9  recursive calls
              0  db block gets
            256  consistent gets
            156  physical reads
              0  redo size
            252  bytes sent via SQL*Net to client
            235  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed

  • How can i find out the more than one times occurance of integer in a array?

    How can i find out the more than one occurance of integer in a array. Assume i have 2,2,3,4,2,5,4,5 in a Array and i need to find out the how many times of 2, 5 and 4 is exists in that array. Please some one help me as sson as possible. thanks in advance....

    Kumar_Mohan wrote:
    How can i find out the more than one occurance of integer in a array. Assume i have 2,2,3,4,2,5,4,5 in a Array and i need to find out the how many times of 2, 5 and 4 is exists in that array. Sort the array. Then loop through it and compare each i-th element with the (i+1)-th element.
    Please some one help me as sson as possible. thanks in advance....In future postings, please refrain from telling that it is urgent, or you need help ASAP. It is rather rude to do so.

  • How can iTunes 4.2 be newer than iTunes 6.0.5?

    I have iTunes 4.2 installed on my G4 running OS 10.3.9 and I want to upgrade to iTunes 6.0.5. When I run the installer and get to the Installation Type window all the packages under action are disabled. If I move the cursor over the word Disabled I get the following message:
    A newer version of this package is already installed.
    How can iTunes 4.2 be newer than iTunes 6.0.5?

    How can iTunes 4.2 be newer than iTunes 6.0.5?
    No idea what makes your Mac think it is.
    Remove the 'iTunes(x).pkg' files from ./Library/Receipts and try installing again.
    M

  • How can I move a title longer than the screen, no the page but just the title in FCP X?

    How can I move a title longer than the screen, not the page but just the title in FCP X?

    Select the title clip in the Timeline, Then Transform. Either click and drag or use the Inspector Position parameters to adjust.
    Russ

  • How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    How can I get the App store to use money in my account rather than a credit card when I want to buy something?

    The iTunes/Mac App Stores use credit on an account first. You are asked to supply an additional payment method when the cash credit doesn't cover the complete cost of the purchase.

  • How can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated

    how can i say yes to automatic updates when they stop my wireless dlink to Virgin home broadband from getting on the internet and then i have to do a system restore to the day before the update to get it back to normal?!? Frustrated
    == This happened ==
    Not sure how often
    == automatic updates go on my computer, say if i click yes to update when shutting down

    You have 10.6 on that machine, I suggest you stick with it for performance, third party hardware and software reasons as long as possible.
    Consider 10.8 (not 10.7) when it's released, because 10.7 and 10.8 will require a new investment in software and newer third party hardware as it requires newer drivers the old machines won't have. (forced upgrade because of software, really nice of them)
    http://roaringapps.com/apps:table
    Far as your Safari problem do these things until it's resolved:
    1: Software Update fully under the Apple menu.
    2: Check the status of your plug-ins and update (works for all browsers) also install Firefox and see if your problems continue. You should always have at least two browsers on the machine just in case one fails.
    https://www.mozilla.org/en-US/plugincheck/
    Flash install instructions/problem resolution here if you need it.
    How to install Flash, fix problems
    3: Install Safari again from Apple's web site
    https://www.apple.com/safari/
    4: Run through this list of fixes, stopping with #16 and report back before doing #17
    Step by Step to fix your Mac

  • How can i give delay of less than 1ms or in micro second?

    how can i give delay of less than 1ms or in terms of micro seconds in labview?

    Hi Kamuil,
    have you seen the following thread?
    http://forums.ni.com/ni/board/message?board.id=170​&message.id=81398&requireLogin=False
    hope this helps.
    Cheers,
    --Russ

  • How can I run Adobe AIR beta until my application is ready to be upgraded?

    How can I run Adobe AIR beta until my application is ready to be upgraded? How can I get around being forced to upgrade? Everything was working fine until the upgrade was forced. This is a huge problem for me

    You can use the Installation Tuner for Reader to customize the UI elements provided to the user.  Details on the Adobe web site.

  • I have iPod shuffle 2nd gen. 1GB, how can I autofill it with more than 70 songs?

    I have iPod shuffle 2nd gen. 1GB, how can I autofill it with more than 70 songs, when I used to be able to get more than l20+ songs?

    Is your shuffle full after the Autofill?  Does the playlist you selected as the source have more than 70 songs?
    My 2nd gen 1GB shuffle currently has 140 songs on it, almost 100% full using Autofill.  The number of songs depends on two factors.  One is the average length of the songs.  Longer songs take more space.  A 20-minute symphony takes more space than a 4-minute pop song.  The other key factor is the bit rate used for compression.
    All of my songs are compressed using the AAC encoder at 256 kbps, which is Apple's current standard and the setting used for downloads from the iTunes Store.  The same songs compressed at 128 kbps AAC takes up half the space.  320 kbps MP3 would use more space per song.  If a lossless format, such as Apple Lossless or AIFF is used to encode, the sound quality is the best possibe, but the file size per song is MUCH higher.
    If you think there is problem on the shuffle, you can try doing a Restore in iTunes.  The Restore button is on the shuffle's Settings tab.  This will erase the shuffle, re-install its software, and set it to default settings. If there is data corruption on the shuffle's storage that is causing this problem, a Restore should fix it.

  • How can i make voiceover read paragraphs than reading the entire page

    how can i make voiceover read paragraphs than reading the entire page of an ebook

    If you are using rectangle as layer or accordion menu then you can use 100% width for these page items.
    In control strip options , when you select the rectangle you can view 100% width button which would make it browser width.
    http://tv.adobe.com/watch/muse-feature-tour/muse-design-for-flexible-browser-width/
    Thanks,
    Sanjit

  • How can i move songs to my playlists using my iphone rather than computer?

    How can I move songs to my playlist using my iphone rather than my computer?

    @allamb & stephanW
    I found this thread via a search, I have a new iphone 5 (also i am completely new to iphone, having been the last few years on android) and i have spent 20 minutes trying to figure out how to add a song to a playlist.
    You see i sit a work and listen to dozens of tunes, and i want to add a paticular song to a particular play list, and low and behold I can't, excuse my special characters but "What the f#%k itunes/apple??? - how can this be? Such a commonly needed function and for itunes to be the number music player in the world not to have this feature is ludicrus.
    I am lucky that i only have about 500 songs on my iphone thus far, i feel sorry for stephanW with 4000+ !!
    Apple - please fix  - this is schoolboy programming stuff...

  • How can I see from my contact who use iphone (ios 5) for contact with imessage?

    How can I see from my contact who use iphone (ios 5) for contact with imessage?

    Well, let take the personal service point of view : let say, I had two calendars on my iCloud account : one for work, one for my leisure activities.
    On my MacBook Pro that I use at home as well as at my office, I would want the two calendars to show and since I am alone in my office, I would want the alerts for both my work and my leisure activities to show (and make a sound at the same time).
    But on my iPad that I only use at home, I would only want my leisure activities alerts to show (and make a sound) and on my iPhone that I only use for work, I would only want my work alerts to show (and make a sound).
    That is a personal service that simply does not work.
    Why would Apple give us the opportunity to hide some calendars on certain devices but not allow us, on these same devices, to switch off the alerts linked to these calendars that we have chosen to hide ? Why having alerts of calendars that do not even show on these devices ?
    And I am an Apple fan since 1984, since the very first Mac. I still do believe Macs and Apple devices and/or software (iOS, OS X and others...) are much better and much more efficient than " Microsoft, Windows, Google and other Android devices and software.
    But that does not mean everything's perfect (and I find that quite normal).
    Nevertheless, in this case, letting alerts make a sound on a device where a specific calendar is not shown, that does not make any sense : when uncheking those calendars, the alerts linked to those calendars should be automatically switch off (but alerts should be able to work on the calendars that are shown.)

Maybe you are looking for

  • External Hard Drive - Not Sure How to Use It

    Hi. My MacBook Pro's main hard drive is pretty much full. I just bought an external hard drive. Is there a way I can (in addition to backing up my most important files) somehow transfer certain files from the computer to the external hard drive (to f

  • Flash player not working in windows 8

    have active x off and player enabled  works fine in chrome.

  • Runtime Error on installation of ATKHTK-Driver - pls help!

    Hello All, last hope for getting solved this ugly problem. Configuration: Lenovo SL500; 2746, 6FG, Windows 7 32 bit - updated; Symptom: While trying to install the ATKHTK-Driver (6AG802WW) manually or with SystemUpdate following error occurs:  Pop-up

  • WiFi keeps disconnecting

    I've just bought a 32GB Touch 3G - latest software. I've got an Apple Time Capsule as my router, wireless enabled and working fine with a laptop. My iPod finds the network no problem, but rejects the password a few times before it will connect. After

  • Inline Element Styles not in DW HTML...

    I have been trying to use a jquery horizontal menu which I downloaded and have successfully implemented it into my dreamweaver page. But I want to adjust the width and height of the actual links <a> tags but the CSS will not allow me to do it I notic