Corellated update AND merge(update only)

Hi ,
I have few corellated updates in my code , which i though ,i can replace with 10g new Merge update only stmt.
But to my surprise , the sql using merge is showing more cost and using full table scan.
Please find below the sql stmts. below(example). Am using Oracle 10.2.0.1
create table t1 as select * from all_objects where rownum<10000;
create table t2 as select * from t1 where rownum<10000-200;
create unique index t1_objId_ind on t1(object_id);
create unique index t2_objId_ind on t2(object_id);
--Corellated updated query
update t1 set t1.object_name= (select upper(t2.object_name) from t2 where t1.object_id=t2.object_id)
where T1.OBJECT_ID IN (SELECT t2.object_id from t2);Explan for above update stmt.
| Id  | Operation                    | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | UPDATE STATEMENT             |              |  9139 |   383K|    37   (9)| 00:00:01 |
|   1 |  UPDATE                      | T1           |       |       |            |          |
|   2 |   NESTED LOOPS               |              |  9139 |   383K|    37   (9)| 00:00:01 |
|   3 |    TABLE ACCESS FULL         | T1           |  9138 |   267K|    35   (3)| 00:00:01 |
|*  4 |    INDEX UNIQUE SCAN         | T2_OBJID_IND |     1 |    13 |     0   (0)| 00:00:01 |
|   5 |   TABLE ACCESS BY INDEX ROWID| T2           |     1 |    30 |     2   (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|*  6 |    INDEX UNIQUE SCAN         | T2_OBJID_IND |     1 |       |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   4 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
   6 - access("T2"."OBJECT_ID"=:B1)I wanted to eliminate the corellated update , So i wrote using MERGE as below
MERGE INTO T2
USING T1
ON (t1.object_id=t2.object_id)
WHEN MATCHED THEN update
  SET T2.OBJECT_NAME=UPPER(T1.OBJECT_NAME);Explan for above MERGE stmt.
| Id  | Operation            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | MERGE STATEMENT      |      |  9139 |   303K|       |   201    (2)| 00:00:03 |
|   1 |  MERGE               | T2   |       |       |       |            |          |
|   2 |   VIEW               |      |       |       |       |            |          |
|*  3 |    HASH JOIN         |      |  9139 |  2391K|  1256K|   201   (2)| 00:00:03 |
|   4 |     TABLE ACCESS FULL| T1   |  9138 |  1142K|       |    35   (3)| 00:00:01 |
|   5 |     TABLE ACCESS FULL| T2   |  9671 |  1322K|       |    34   (3)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
   3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")Cost is 201 , but for the corellated update the cost is 37.
Any idea , how should i re-write the MERGE stmt.?
Edited by: kumar on Jun 16, 2011 4:41 PM

First "cost" is just a number and you should not compare or tune to get the best "cost" in an execution plan.
What counts ist elapsed time => IO, CPU...
In 11g the "cost" for the merge is better (and also the CPU time is far off to be close to the truth!)
9799 rows updated
78ms elapsed
Plan hash value: 580992724
| Id  | Operation                    | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | UPDATE STATEMENT             |              |  9641 |   404K| 28964  (34)| 00:05:48 |
|   1 |  UPDATE                      | T1           |       |       |            |          |
|   2 |   NESTED LOOPS               |              |  9641 |   404K|    41   (3)| 00:00:01 |
|   3 |    TABLE ACCESS FULL         | T1           | 10866 |   318K|    40   (0)| 00:00:01 |
|*  4 |    INDEX UNIQUE SCAN         | T2_OBJID_IND |     1 |    13 |     0   (0)| 00:00:01 |
|   5 |   TABLE ACCESS BY INDEX ROWID| T2           |     1 |    30 |     2   (0)| 00:00:01 |
|*  6 |    INDEX UNIQUE SCAN         | T2_OBJID_IND |     1 |       |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   4 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
   6 - access("T2"."OBJECT_ID"=:B1)
Note
   - dynamic sampling used for this statement (level=2)
commited
16ms elapsed
9799 rows merged
125ms elapsed
Plan hash value: 2009158753
| Id  | Operation            | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
|   0 | MERGE STATEMENT      |      |  9641 |   320K|       |   251   (1)| 00:00:04 |
|   1 |  MERGE               | T2   |       |       |       |            |          |
|   2 |   VIEW               |      |       |       |       |            |          |
|*  3 |    HASH JOIN         |      |  9641 |  3088K|  1720K|   251   (1)| 00:00:04 |
|   4 |     TABLE ACCESS FULL| T2   |  9640 |  1600K|       |    39   (0)| 00:00:01 |
|   5 |     TABLE ACCESS FULL| T1   | 10866 |  1676K|       |    40   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
Note
   - dynamic sampling used for this statement (level=2)In your example, the elapsed time (thanks for the it!) is 78ms for the update and 125ms for the MERGE. (ORACLE 11g on and old PC) .
So "should you rewrite" the MERGE? No idea how. I assume you want to change from UPDATE to MERGE and see if it's worth?
Here it's not. But, your example just uses 2MB of data. And the difference from my point view is not MERGE or UPDATE it's NL against HASH join with that tiny amount of data.
So generally I use MERGE because of speed and because I have more control over the query. For updating 2MB of data, it's not worth it. For updating GBytes the stuff I worked on it was faster (and better to control).

Similar Messages

  • What if my ipod touch 4th generation can't update and now the only option is to restore it. And i don't know what happens if i press restore?

    What if my ipod touch 4th generation can't update and now the only option is to restore it.
    And i don't know what happens if i press restore?
    Will it show my back up and back it up or what?
    And if that does happen will all my pictures stil be there?
    Also i'm not on a apple computer.

    To restore from backup see:
    iOS: Back up and restore your iOS device with iCloud or iTunes       
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:           
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    Either a PC or Mac work the same.
    The photos in our iPod's Camera Roll album will be restored as will the last 30 days of photos in our PhotoStream album

  • HT4623 help me to troubleshoot my ipad2 there is software update and i updated mine from 5.0 to 6 version but now the screen shows only usb cord arrow up sign then itunes and music logo. it has been like this since last night.what i will do?

    help me to troubleshoot my ipad2 there is software update and i updated mine from 5.0 to 6 version but now the screen shows only usb cord arrow up sign then itunes and music logo. it has been like this since last night.what i will do?i even tried turning it off but it doesnt work too. i only see the apple logo and it comes back to cord image and itune then after 30 secs the screen turns black. help me please.

    The iPad is telling you to connect your iPad to iTunes on your computer so do it. You may have to restore the device.
    Restoring iOS Software.
    http://support.apple.com/kb/ht1414
    You may need this as well.
    Unable to update or restore iPad.
    http://support.apple.com/kb/ht4097

  • HT1365 How can I get my iPhone 4 to update my updates from my app store of it keeps telling me error 3150 or it tell me to refresh the page after updates and the updates are still there asking me to update them again

    How can I get my iPhone 4 to update my updates from my app store of it keeps telling me error 3150 or it tell me to refresh the page after updates and the updates are still there asking me to update them again?

    Make sure iTunes on the computer is logged into the account on the phone.
    Plug the iPhone in.
    In the popup window warning about wiping your phone, hit cancel.
    In the left pane of iTunes, the phone icon should be there.
    Right click on it, select transfer purchases.
    Note: this will only transfer music bought from iTunes. Not mp3's from amazon or ripped from CD's.

  • Service Packs, Security Updates and Cumulative Updates

    I would like to find a  document that would help me understand and clarify Service Packs, Security Updates and Cumulative Updates versions and relationships.
    Things like. Cumulative Updates include old Security Updates. Cumulative Updates do not overwrite applied Security Updates, etc.
    For instance,
    I am upgrading a server from: 10.0.5512 (SQL 2008 SP3, After Security Update MS12-70)  To: 10.0.5861 (SQL 2008 SP3 CU17).
    Would the MS12-70 (2754849) I installed still be present after installing CU17? The reason for doubt was that I saw another version of MS12-70 that includes
    CU 1 to 7(KB2716435). So makes me wonder about it.
    I am probably not able to explain myself right but, the idea is to find a document that can explain how the build information and versioning works. 
    Some how I have the idea that Cumulative updates would not include Security Updates.
    Thanks beforehand
    Paulino

    Hi,
    Below will give you list of Service packs and Cumulative updates for SQL Server
    http://support.microsoft.com/kb/321185
    http://sqlserverbuilds.blogspot.co.uk/
    Security updates are for Windows not SQL Server. SQL server releases Cumulative updates after that a comprehensive service pack is released which includes all fixes that were done in Cumulative updates.
    Cumulative updates fix only a certain type of problem(for which they are created) and should only be applied if facing issue
    Service packs are more through and Inclusive and should be applied and contains many fixes and sometimes introduces few features as well. SP are more thoroughly tested as compared to CU For Cumulative
    update from Microsoft:
    We recommend that you test hotfixes before you deploy them in a production environment.
    This cumulative package is intended to correct only the problems that are described in this article. Apply it only to systems that are experiencing these specific problems.
    This cumulative update contains all the hotfixes and all the updates that were included with the previous SQL Server 2014 update release.
    Windows patch has hardly any relation to SQL server SP and CU.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • Differnce b/w flexible update and direct update

    Hi gurs,
    please tell me the difference between flexible update and direct update.
    Rakesh

    Hi Rakesh,
       Normally  when we upload the master data we can select DIRECT UPDATE .. or Flexible update... ..
      if you select Direct Update means.. there is no need to create  Update rules..
    but this is only  possible for master data..
       if you select  Flexible update means..  we  need to cretae Update Rules also..,  this is mainly for transactional data..
    Direct update is generally used for Master data infoobject & here no update rules are used, that means data from source system passes though transfer structure, rules, & communication structure directly to Data target i.e. InfoObject.
    Flexible Update - generally used for transaction data ( nowadays can be used for few master data as well) has another set of rule after communication structure i.e. update rule before moving data to data target.
    Re: Flexible Update Vs Direct Update?
    Flexible update of Master data
    Re: Flexible update Vs direct update.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/37dda990-0201-0010-198f-9fdfefc02412
    thanks
    @jay

  • Unable to run bapis for project status update and date update together

    Hi Experts,
    I have a requirement to update the dates and status of a project WBS at level 4. I am trying to do update the CJ02 Transaction using standard BAPI available. I need to do both Date update and status update in the same LOOP PASS   i am using the below mention bapi. when i am doing so i am getting an error Project 'A._____' has been currently processed by ID i.e. my id.
    I have tried putting  a wait for 2 seconds in the code but its still not working. please find the order below in which i am calling the bapi.
    Loop at itab.
    if  date_changed = 'X'.
          CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'
          READ TABLE it_error WITH KEY message_type = c_e.
          IF sy-subrc <> 0.
    Commit
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                 EXPORTING
                      wait   = c_x
                 IMPORTING
                      return = s_ret.
       endif.
    endif.
    if Status_change = 'X'.
          CALL FUNCTION 'BAPI_PS_INITIALIZATION' .
          CALL FUNCTION 'BAPI_BUS2054_SET_STATUS'
          READ TABLE t_result WITH KEY message_type = c_e.
          IF sy-subrc NE 0.
            CALL FUNCTION 'BAPI_PS_PRECOMMIT'
                 TABLES
                      et_return = t_ret.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                 EXPORTING
                      wait   = c_x
                 IMPORTING
                      return = s_ret.
         ENDIF.
    endif.
        WAIT UP TO 4 SECONDS.
    endloop.

    Try to use
    SET UPDATE TASK LOCAL.
    before each BAPI call.
    Did you try to debug through your code, leaving sufficient time between BAPI calls? If it does work like that, then the above statement might help.

  • So my phone is plugged into the computer for a software update and the update went halfway through and hasnt made any advancements. how do i get my phone back without losing anything?

    so my phone is plugged into the computer for a software update and the update went halfway through and kind of stopped. it says its still updating but I cant figure out how to stop it and just get my phone back. how do i get my phone back without losing anything?

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • Just downloaded latest update and saw updates for fingerprint scanners. Do I have a fingerprint scanner or where do I get one?

    Just downloaded latest update and saw updates for fingerprint scanners. Do I have a fingerprint scanner or where do I get one?

    If you have an I phone 5s you have a scanner.  It does not exist on any other device at this point, and cannot be added.

  • Since this morning when I try Software Updates and then Updates, I get a consistent message - An Error has occurred, The operation couldn't be completed. (NSURLErrorDomain error - 1012). Is this a server error and what do I do next?

    Since this morning when I try Software Updates and then Updates, I get a consistent message - An Error has occurred, The operation couldn't be completed. (NSURLErrorDomain error - 1012). Is this a server error and what do I do next?
    Please help!!!!!

    Wait until Apple fixes this server issue.
    Best.

  • Direct update and flexible update

    Hi BWers,
    I want to know the difference between direct update and flexible update in detail. Could someone explain me in detail with an example? or send me some documents explaining this clearly?
    Regards,
    RV.

    hi
    Using the fleixble update method for master data loads you need to create update rules for the
    InfoSource and the InfoObject. The direct update loads the data directly without going through the
    update rule layer.
    The presence of Update Rules allows for extra processing and data transformation capability. Also the
    flexible update makes it possible to load data from several sources to the InfoObject, since all
    you need to do it to create update rules between the InfoSource and your InfoObject. An example
    of using this is when you need to populate certian master data attributes but the data is
    coming as transaction data. Sometimes the descriptions are also a part of transaction data,
    whereas you may want to load them as text rather than in the cube (this happens a lot in CRM datasources).
    So here flexible updates are useful.
    check these links also
    http://help.sap.com/saphelp_nw04/helpdata/en/98/3a14836fe5e1499a4e17d2d45f4612/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/86/cade377806e664e10000009b38f842/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/41/56ba275e032f1ee10000000a114b54/frameset.htm
    http://help.sap.com/search/highlightContent.jsp
    Regards,

  • Diff between statistics update and document update

    Hi Everybody,
                Can any  one explain the difference between the statistics update and document update with an example.

    Hello Raju,
    Also go through these threads
    statistical update and document update
    V1,V2,V3 updates
    Regards,
    Praveen

  • Difference between the synchrous update and asynchrous update

    Hi all,
    Can anybody explain the me the difference between the synchrous update and asynchrous update with some example.
    Thanks in advance
    Ramya

    Hi,
      Message: A Asynchronous updating. In this mode, the called transaction does not wait for any updates it produces to be completed. It simply passes the updates to the SAP update service. Asynchronous processing therefore usually results in faster execution of your data transfer program.
    Asynchronous processing is NOT recommended for processing any larger amount of data. This is because the called transaction receives no completion message from the update module in asynchronous updating. The calling data transfer program, in turn, cannot determine whether a called transaction ended with a successful update of the database or not.
    If you use asynchronous updating, then you will need to use the update management facility (Transaction SM12) to check whether updates have been terminated abnormally during session processing. Error analysis and recovery is less convenient than with synchronous updating.
    S Synchronous updating. In this mode, the called transaction waits for any updates that it produces to be completed. Execution is slower than with asynchronous updating because called transactions wait for updating to be completed. However, the called transaction is able to return any update error message that occurs to your program. It is much easier for you to analyze and recover from errors.
    L Local updating. If you update data locally, the update of the database will not be processed in a separate process, but in the process of the calling program. (See the ABAP keyword documentation on SET UPDATE TASK LOCAL for more information.)
    Regards

  • Statistics update and docuement update

    hai,
          can any one explain the differences between statitics update and docuement update . and please explain how these updates are happen in the lo-cockpit extraction method.and wht are the differences between v1 ,v2 and v3 updates.
    thanks,
    sri

    Hi Sri!
    Look here
    /people/sap.user72/blog/2005/01/19/logistic-cockpit-delta-mechanism--episode-three-the-new-update-methods
    /people/sap.user72/blog/2005/01/19/logistic-cockpit-delta-mechanism--episode-three-the-new-update-methods
    and all my related weblogs...
    Hope it helps!
    Bye,
    Roberto
    ...please don't forget to reward the answers...it's THE way to say thanks here...

  • UPDATE GONE BAD! I ran the new update and my phone only has a picture of a USB and the I Tunes Music note? I plug it in and it says I must restore to the original setting losing everything? Is there hope?

    Can anyone help me get my phone working and  retain my data? I Ran the latest I Tunes update (6.0)and my phone (3GS) froze on the USB Itunes screen and my computer I Tunes says I must restore to factory settings losing all data?

    Yes I had the same problem with my iPhone 4. What I did was connected my phone to my computer. itunes popes up and said that they have discovered a iphone in recovery mode. it asked if i wanted to update and restore. I clicked yes and it download the ios6 update on iTunes on my computer and then did the update on my phone through that. I got the same message and I thought that I would lose everything too, but I did not.

Maybe you are looking for

  • Am I getting charged for things way after I download them?

    I tried to download something FREE. It said to check my billing information. I did that and then it charged my credit card two dollars, why? Then when I downloaded another FREE app, it charged me again. I did not have that money on the card now I hav

  • I-tunes wont download podcasts or purchased music

    I keep getting the same error message when trying to subscribe to a podcast or purchase music from the i-tunes store saying you have entered a wrong url and you are not connected to the internet when i cam check and listen to the songs on the store o

  • Multiple Queries on Same/Different Table?

    Hello all, I have started to learn how to integrate java with databases using JDBC. However I have a question that would make my life much easier. From what I've learned everytime I want to do a query, I have to create a new statement and new result

  • Link to fold on shared drive from PDF

    Hi all, I have a PDF document that I would like a text box to link (open a shared drive)to a shard folder drive. I have tried the file:/// (path) but it does not work. I basically want a visual box a user clicks to go to the specific folder on the dr

  • Wildcard certifications in Weblogic 5.1,SP8

    Has anyone had success in using Thawte's wildcard SSL certificates which are supposed to work with weblogic and allow for multiple sub domains? We have many subdomains running from one weblogic instance that is also clustered across several servers t