简体   繁体   中英

oracle SQL query Optimization

SELECT SHIP.SHIPID, SHIP.SHIPID_SFX, SHIP.DATE_SOURCE, SHIP.DATE_SHIP, SHIP.WT_TOTAL, SHIP.LINK, SHIP.CARR,
MBSH.MB_ID, MBSH.MB_ID_SFX
, FBIL.DATE_BILL, FBIL.DATE_CHECK, FBIL.STATUS
FROM SHIP,
     MBSH,
    SFXR,
     FBIL
WHERE SHIP.DATE_SOURCE Between '2012/08/31' And '2012/09/28' 
AND SUBSTR(SHIP.CARR,1,1) = 'C'
AND substr(SHIP.CARR,2,1) between '0' and '9' 
And SHIP.CARR not in ('7','41','11','15')
AND SHIP.MOVE_MB Is Null 
AND SHIP.SOURCE03='JDE'
And MBSH.MB_SHIPID_SFX = SHIP.SHIPID_SFX
AND MBSH.MB_SHIPID = SHIP.SHIPID
And SFXR.SHIPID = SHIP.SHIPID
And SFXR.SHIPID_SFX = SHIP.SHIPID_SFX
And SFXR.CARR = SHIP.CARR
And FBIL.BILL_ID = SFXR.BILL_ID
And FBIL.BILL_BD = SFXR.BILL_BD

This is my query joining 4 tables. the sfxr table holds refrence to the ship and bill table. need to use it to get bill data using ship data. The above query runs forever. Can it be optimized or needs to be done through the application code.

First clean up

convert the parameters to dates

SHIP.DATE_SOURCE Between '2012/08/31' And '2012/09/28'    
SHIP.DATE_SOURCE Between to_date('2012/08/31','YYYY/MM/DD') And to_date('2012/09/28','YYYY/MM/DD')

Drop the NOT IN the values do not start with 'C' so it's dedundant. Use the between as Bob suggested.

AND SUBSTR(SHIP.CARR,1,1) = 'C'    
AND substr(SHIP.CARR,2,1) between '0' and '9'       
-- AND SHIP.CARR not in ('7','41','11','15') 

For us to be able to help you we need you to do the following:

  1. run statistic on the database (maybee use histograms).
  2. Show us the indexes you have defined on the table
  3. Then show us an explain plan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM