Results 1 to 2 of 2

Thread: Update query

  1. #1
    Join Date
    Jan 2004
    Location
    India
    Posts
    191

    Unanswered: Update query

    Hi,
    Could anyone please give some tips to tune the below update query.

    PHP Code:
    declare
      
    Cursor C Is Select DB_CODE from  DB_MASTER
        Where DB_CODE in 
    ('1100','1160','1200','1361','1410','1453',
          
    '1456','1460','1480','1490','1492','1580','1581','1600',
          
    '1700','1750','1800','1850','1903','1950','2065','2200',
          
    '2355','2405');
    begin
    For C_rec in C Loop
    Update 
     BOOKING_LINE BO
    Set 
    (REQ_DATE,DUE_DATE,PER_DATE) = 
    (
    Select 
    BI
    .REQ_DATE,BI.DUE_DATE,BI.PER_DATE
      From  BOOKING_LINE BI
      Where BI
    .DB_CODE=C_rec.DB_CODE
        
    And BO.DB_CODE=C_rec.DB_CODE
        
    And BI.TRANSACTION_NUMBER 
          (
    Select 
    Max 
    (BM.TRANSACTION_NUMBER)
             
    From  BOOKING_LINE BM
             Where BM
    .TRANSACTION_NUMBER BO.TRANSACTION_NUMBER 
                 
    And BM.ORDER_NUMBER BO.ORDER_NUMBER
                 
    And BM.ORDER_LINE BO.ORDER_LINE
                 
    And BM.CUST_SOLD_ID BO.CUST_SOLD_ID
                 
    And BM.ITEM_ID BO.ITEM_ID
                 
    And BM.QUANTITY 0
          
    )
         And 
    BI.ORDER_NUMBER BO.ORDER_NUMBER
         
    And BI.ORDER_LINE BO.ORDER_LINE
    )
    Where BO.QUANTITY 0
        
    And (BO.REQ_DATE,BO.DUE_DATE,BO.PER_DATE) <> 
    (
    Select 
    BI
    .REQ_DATE,BI.DUE_DATE,BI.PER_DATE
      From  BOOKING_LINE BI
      Where BI
    .DB_CODE=C_rec.DB_CODE
        
    And BO.DB_CODE=C_rec.DB_CODE
        
    And BI.TRANSACTION_NUMBER 
          (
    Select 
    Max 
    (BM.TRANSACTION_NUMBER)
             
    From  BOOKING_LINE BM
             Where BM
    .TRANSACTION_NUMBER BO.TRANSACTION_NUMBER 
                 
    And BM.ORDER_NUMBER BO.ORDER_NUMBER
                 
    And BM.ORDER_LINE BO.ORDER_LINE
                 
    And BM.CUST_SOLD_ID BO.CUST_SOLD_ID
                 
    And BM.ITEM_ID BO.ITEM_ID
                 
    And BM.QUANTITY 0
          
    )
         And 
    BI.ORDER_NUMBER BO.ORDER_NUMBER
         
    And BI.ORDER_LINE BO.ORDER_LINE
    )
        And 
    DB_CODE =C_rec.DB_CODE
        
    And CUST_SCHED <>'Y'
    and fiscal_week =200453;
    Commit;
    End Loop;
    end
    Number of records in booking_line 18454211

    Indexes on booking_line
    PHP Code:
    INDEX_NAME                     COLUMN_NAME
    ------------------------------ ---------------
    I_BOOKING_BILL_TO              CUST_BILL_ID
    I_BOOKING_ITEM                 ITEM_ID
    I_BOOKING_LINE_ORIGIN          ORDER_ORIGIN
    I_BOOKING_SHIP_CODE            DB_CODE
    I_BOOKING_SHIP_CODE            CUST_SHIP_CODE
    I_BOOKING_WEEK                 FISCAL_WEEK
    I_BOOKING_WEEK_2               FISCAL_WEEK
    I_BOOKING_WEEK_2               DB_CODE
    PK_BOOKING                     DB_CODE
    PK_BOOKING                     ORDER_NUMBER
    PK_BOOKING                     ORDER_LINE
    PK_BOOKING                     TRANSACTION_NUMBER 
    Thanks in advance
    Pagnint
    (No need to search web before posting new question)

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    How about this?
    Code:
    begin
      Update
      BOOKING_LINE BO
      Set (REQ_DATE,DUE_DATE,PER_DATE) =
      (Select
      BI.REQ_DATE,BI.DUE_DATE,BI.PER_DATE
        From  BOOKING_LINE BI
        Where BI.DB_CODE=BO.DB_CODE
          And BI.TRANSACTION_NUMBER =
            (Select
      Max (BM.TRANSACTION_NUMBER)
               From  BOOKING_LINE BM
               Where BM.TRANSACTION_NUMBER < BO.TRANSACTION_NUMBER
                   And BM.ORDER_NUMBER = BO.ORDER_NUMBER
                   And BM.ORDER_LINE = BO.ORDER_LINE
                   And BM.CUST_SOLD_ID = BO.CUST_SOLD_ID
                   And BM.ITEM_ID = BO.ITEM_ID
                   And BM.QUANTITY > 0
            )
           And BI.ORDER_NUMBER = BO.ORDER_NUMBER
           And BI.ORDER_LINE = BO.ORDER_LINE
      )
      Where BO.QUANTITY < 0
          And DB_CODE in ('1100','1160','1200','1361','1410','1453',
            '1456','1460','1480','1490','1492','1580','1581','  1600',
            '1700','1750','1800','1850','1903','1950','2065','  2200',
            '2355','2405')
          And CUST_SCHED <>'Y'
      and fiscal_week =200453;
      Commit;
    end;
    Changes made:
    1) Do all updates in one go, rather than within a loop.
    2) Removed the check on whether the update is necessary - so more rows will be updated, but less work will be done in determining the rows to update.
    3) Some redundant joins on DB_CODE removed.

    You could try all these changes together or one at a time to see what helps.

Posting Permissions

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