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

Similar Messages

  • I purchased an ablum thru itunes on my phone and it says i purchased the songs on itunes but when i go on my music it says i have to repurchase all the songs how can i get the songs with out havin to pay again

    I purchased an ablum thru itunes on my phone and it says i purchased the songs on itunes but when i go on my music it says i have to repurchase all the songs how can i get the songs with out havin to pay again

    Whether you can redownload music depends upon what country that you in. If you are using your computer's iTunes then does music show in the Purchased link under Quicklinks on the right-hand side of the iTunes store home page (on your phone you might be able to redownload media via the Purchased tab in the iTunes store app) ? If music shows there, but not that album, then check to see if it's hidden : http://support.apple.com/kb/HT4919
    If you aren't in a country when you can redownload music and it's still on your phone then you should be able to copy it over from the phone via File > Devices > Transfer Purchases.

  • HT1386 The laptop I originally synch'd my iphone 4s with is broken and cannot retrieve any files. How can I sync the phone with a new laptop without losing all my downloaded music and apps already installed on my iphone?

    The laptop I originally synch'd my iphone 4s with is broken and cannot retrieve any files. How can I sync the phone with a new laptop without losing all my downloaded music and apps already installed on my iphone?

    If the answer to the above question is "yes", FIRST, set up a backup of your new computer before you do anything else so the next time your computer breaks you will not be in the same situation. Backup solutions are numerous and inexpensive, and there is absolutely no excuse in the Third Millennium not to have one.
    Then see this tip: https://discussions.apple.com/docs/DOC-3141

  • How can I use the DBAdapter with SequencingPollingStrategy in OSB Cluster?

    Hi!
    I have a OSB cluster. I need to read a view with the DBAdapter. I use SequencingPollingStrategy to implement the adapter.
    Then I import it into OSB and make it work and the service works normally in the single node.
    But if I import it into OSB cluster, the service always read the duplication records from the view.(the Distrbute polling is not worked in SequencingPollingStrategy )
    So how can I use the DBAdapter with SequencingPollingStrategy in OSB Cluster?
    Thank you!

    Nope. Version 5 is a fashion accessory: it looks like software, but it doesn;t actually do anything. Sort of like a sports car with a lawn-mower engine. Looks snzzy. Doesn't really work. (And given how buggy it is, I should further specifiy that the lawn-mower engine comes with a blade: it chews up your old templates, produces files that cannot be sent as email attahcments [yes, really], and—this just in—doesn;t play well with the new SMB facility of Mavericks. In short, as one reviewer put it, "un unmitigated disaster."

  • How can I get the variable with the value from Thread Run method?

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    // I should get Inside the run method::: But I get only Inside
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    We want to access a variable from the run method of a
    Thread externally in a class or in a method. I presume you mean a member variable of the thread class and not a local variable inside the run() method.
    Even
    though I make the variable as public /public static, I
    could get the value till the end of the run method
    only. After that scope of the variable gets lost
    resulting to null value in the called method/class..
    I find it easier to implement the Runnable interface rather than extending a thread. This allows your class to extend another class (ie if you extend thread you can't extend something else, but if you implement Runnable you have the ability to inherit from something). Here's how I would write it:
    public class SampleSynchronisation
      public static void main(String[] args)
        SampleSynchronisation app = new SampleSynchronisation();
      public SampleSynchronisation()
        MyRunnable runner = new MyRunnable();
        new Thread(runner).start();
        // yield this thread so other thread gets a chance to start
        Thread.yield();
        System.out.println("runner's X = " + runner.getX());
      class MyRunnable implements Runnable
        String X = null;
        // this method called from the controlling thread
        public synchronized String getX()
          return X;
        public void run()
          System.out.println("Inside MyRunnable");
          X = "MyRunnable's data";
      } // end class MyRunnable
    } // end class SampleSynchronisation>
    public class SampleSynchronisation
    public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run
    method "+sathr.x);
    // I should get Inside the run method::: But I get
    only Inside
    class sampleThread extends Thread
    public String x="Inside";
    public void run()
    x+="the run method";
    NB: if i write the variable in to a file I am able to
    read it from external method. This I dont want to do

  • How can I get the variable with the value from Thread's run method

    We want to access a variable from the run method of a Thread externally in a class or in a method. Even though I make the variable as public /public static, I could get the value till the end of the run method only. After that scope of the variable gets lost resulting to null value in the called method/class..
    How can I get the variable with the value?
    This is sample code:
    public class SampleSynchronisation
         public static void main(String df[])
    sampleThread sathr= new sampleThread();
    sathr.start();
    System.out.println("This is the value from the run method "+sathr.x);
    /* I should get:
    Inside the run method
    But I get only:
    Inside*/
    class sampleThread extends Thread
         public String x="Inside";
         public void run()
              x+="the run method";
    NB: if i write the variable in to a file I am able to read it from external method. This I dont want to do

    Your main thread continues to run after the sathr thread is completed, consequently the output is done before the sathr thread has modified the string. You need to make the main thread pause, this will allow sathr time to run to the point where it will modify the string and then you can print it out. Another way would be to lock the object using a synchronized block to stop the main thread accessing the string until the sathr has finished with it.

  • How can I disable the advancedAntiAliasing with fontswf in sdk

    Hi,
    in asc2.0 we need 'fontswf' script to embed fonts instead of use .as file directly.
    but here is a problem
    I cannt disable the advancedAntiAliasing with fontswf ?
    because I have found an issue when I set advancedAntiAliasing is true, then the textfield (which font is embeded) antiAliasType doesn't work even type is advanced. I need set advancedAntiAliasing is false (in asc1.0 you can set it by .as file)
    now i just set the sharpness and thickness to workaround in used asc2.0
    but i think that is not great.
    so how can I disable the advancedAntiAliasing with fontswf  or any other solution?
    thanks
    hbb

    Hello -
    That setting is not fully supported.  You can explicitly call it like this:
    ./compc -include-sources  ../samples/test/Main.as -output ../samples/test/Main.swf -advanced-anti-aliasing=true/false
    So, that is the compiler option that you want to use in order to disable it.  The example I show you here uses the command line tool but it is a valid switch via Flash Builder as well

  • How can I search the tree with a given string?

    How can I search the tree with a given string?
    I don't find any function like "search(...)".
    I want to find the tree nodes which include the given string.
    Thanks.

    Try it with .com instead of .ca - fixes it for me (corporate firewall blocks .ca here)
    http://spendolini.blogspot.com/2013/09/working-with-apex-tree.html
    Anyway - it links to an article of mine which describes interacting with the tree: Tom's Blog: Working with the tree in Apex. There is also a demo application on apex.oracle.com: http://apex.oracle.com/pls/apex/f?p=54687:38

  • How can I use the ScrollTablePane with kodo ?

    How can I use the ScrollTablePane with kodo, taking a result Query as
    a Collection and throw it into the ScrollTablePane , if it not possible ,
    Is there a Component which I can do it ?
    Thanks , Marco Aurelio.

    Marco-
    I am not familiar with any "TableScrollPane" classes. Can you clarify
    whether this is some 3rd party custom component, or something you have
    written?
    Note that we do not provide any pre-build graphical data components with
    Kodo, but we do intend to provide some examples in the future.
    In article <cl1hn7$9ep$[email protected]>, Marco Aurelio Bueno wrote:
    >
    How can I use the TableScrollPane with kodo, taking a result Query as
    a Collection and throw it into the ScrollTablePane , if it not possible ,
    Is there a Component which I can do it ?
    Thanks , Marco Aurelio.--
    Marc Prud'hommeaux
    SolarMetric Inc.

  • How can I use the TableScrollPane with kodo

    How can I use the TableScrollPane with kodo, taking a result Query as
    a Collection and throw it into the ScrollTablePane , if it not possible ,
    Is there a Component which I can do it ?
    Thanks , Marco Aurelio.

    Marco-
    I am not familiar with any "TableScrollPane" classes. Can you clarify
    whether this is some 3rd party custom component, or something you have
    written?
    Note that we do not provide any pre-build graphical data components with
    Kodo, but we do intend to provide some examples in the future.
    In article <cl1hn7$9ep$[email protected]>, Marco Aurelio Bueno wrote:
    >
    How can I use the TableScrollPane with kodo, taking a result Query as
    a Collection and throw it into the ScrollTablePane , if it not possible ,
    Is there a Component which I can do it ?
    Thanks , Marco Aurelio.--
    Marc Prud'hommeaux
    SolarMetric Inc.

  • HOW CAN I PUT THE AMOUNT WITH THE SIGN OF DOLLAR?

    HI!
    HOW CAN I PUT THE AMOUNT WITH THE SIGN OF DOLLAR?
    BECAUSE WHEN I WRITE THE DATA THE AMOUNT OVERWRITE THE SIGN.
    THANKS PEOPLE

    THIS IS THE WRITE PART:
    [code]
    WRITE:
              /97 t_bsid-dmbtr,          "Invoice Amount
              104 '$',
              104 t_bsid-fecha,          "Payment Date
              114 t_bsid-pago,           "Payment Amount
              116 '$'.
    [/code]

  • How can I make the popup with empty fileds and create new record?

    I would like to use a popup to create new record.
    I created a af:popup by drag and drop a VO from data control to jsff. then, I created a button and place a af:showPopupBehavior. I was able to popup window by click the button.
    however, the window filled with the information from the 1st record. and when I select a record in table and click popup, the popup is filled with that record.
    How can I make the popup with empty fileds and create new record by saving the popup?
    Thanks

    You can have edit and new buttons, in the PopupFetchEvent identify button source (using popupFetchEvent.getLaunchSourceClientId()) if new button clicked clear the binding using below code.
    If you want to see empty fields, in the popup PopupFetchEvent clear the input component bindings.
    resetBindingValue("#{bindings.<componentid>.inputValue}", null);
        public static void resetBindingValue(String expression, Object newValue) {
            FacesContext ctx = FacesContext.getCurrentInstance();
            Application app = ctx.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = ctx.getELContext();
            ValueExpression valueExp = elFactory.createValueExpression(elContext,expression,Object.class);
            Class bindClass = valueExp.getType(elContext);
            valueExp.setValue(elContext,newValue);
        }

  • How can I change the language with the .dat (.bak) file?

    How can I change the language with the .dat (.bak) file? Is it legal?
    How does it work?
    Thanks for answering

    https://discussions.apple.com/message/17364930#17364930

  • How can i do the RAC with Oracle 9i ?

    How can i do the RAC with Oracle 9i ?
    The Oracle 9i has a RAC(Real Application Cluster)module , please who can tell me how can i let it working .
    Which hardware the RAC need's
    Thank All ,
    [email protected]

    That is right you need atleast 2 boxes. The two servers will use the same hard disks.
    The concept is an extension of OPS(Oracle Parallel Server).
    Basically, you install Oracle Server Software on both the boxes, One database will be shared by both the servers. You can access your database through the Server1 or Server2. If Server1 fails then the Server2 will take over all the connections. You can add or remove any servers to and from the cluster any time you want with out impacting your production.
    They share load, reliable, scalable....

  • How can i unlock the service with AT&T or other carrier? when i was in overseas ?how much does it cost to unlock?

    how can i unlock the service with AT&T or other carrier? when i was in overseas ?how much does it cost to unlock?

    The only way to unlock a locked device is through the carrier. If it is locked to AT&T, you will have to contact them to get it unlocked.
    Cheers,
    GB

Maybe you are looking for

  • How do I delete just the first page of a document?

    A long time ago (2005) I made a document over 200 pages long - and now I need to edit it, specifically to delete the first (empty) page of the documet, so when I add a separate cover, the first page will be on the right, where it should be. I shall a

  • Canon GL-2 compatability with I Movie?

    Hi. I am looking into the Canon GL-2 for use with imovie and FCE. Does anyone have experience with this? Any advice would be great. I am filming sit down interviews in people's homes.

  • How do I get rid of malware entries in my Prefs.js file (stored in my profile folder)?

    I want to get rid of anything that contains the string "claro" in it. Here is part of my prefs.js file that shows what I want to clear: \Mozilla\\\\Firefox\\\\Profiles\\\\a6s51y6q.default-1347242978286\\\\extensions\\\\{d10d0bf8-f5b5-c8b4-a8b2-2b9879

  • I cannot use the Camera Raw feature

    I cannot use the Camera Raw feature after updating the CC!!!

  • Serial Send speed

    Hi all I want to read an array of 2500bytes from serial port with bouad rate set to 2,000,000 bit/sec. I'm supposed to have 2500 bytes 100 times in every seccond ((2000000/8)/2500) ,but I just have it 3 or 4 times in a seccond... what should I do? Th