DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Quick code tune required

  1. #1
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346

    Quick code tune required

    Hi code gurus,

    Quick help required....

    Is there a better way to code this..... Many thanks

    Code:
    update trans t 
     set t.cmp = 'Feb' where exists  
       (select *   from
        CMPFebTest c   
        where  c.account_number = t.account_number   
        and     t.effective_date  <= c.End_Date   
        and     t.effective_date >= c.contact_date)

  2. #2
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    have you tried update view?

  3. #3
    Join Date
    Sep 2005
    Posts
    278
    Code:
    UPDATE (SELECT t.cmp 
                FROM trans t, CMPFebTest t
                WHERE  c.account_number = t.account_number   
                AND t.effective_date  <= c.End_Date   
                AND t.effective_date >= c.contact_date
    	    )
    SET t.cmp = 'Feb'
    
    --OR
    
    MERGE INTO trans t
    USING (SELECT account_number
    	FROM CMPFebTest 
    	WHERE t.effective_date  <= c.End_Date   
    	AND     t.effective_date >= c.contact_date
    	)c
    ON (t.account_number = c.account_number)
    WHEN MATCHED THEN
    UPDATE SET t.cmp = 'Feb'

  4. #4
    Join Date
    May 2005
    Location
    Boracay
    Posts
    681
    Hi Horace,....feedback pls if the performance improved with
    the rew code

  5. #5
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346
    Oops. Sorry Guys.

    Tabreaz, thanks very much for those alternatives.

    To be honest, I was maxed out when this problem arose. One of the developers had been running this on one of our many databases for 20 hours, and still running. When I finally got to looking at it, the PLAN was horrendous with a FILTER in it. Noticed that neither table was ANALYZED.

    So quick fix, and the code ran in under 30 seconds!! The FILTER was replaced with HASH JOINS, once the CBO had a clue.

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width