带索引的SQL优化

时间:2017-03-29 09:14:08

标签: sql query-optimization oracle-sqldeveloper

我一直在努力使用索引代替where子句来优化下面的查询。可以任何人帮助相同。数据量非常高,所以我想使用索引或其他方式对其进行优化?

查询是这样的:

SELECT * 
FROM 
    (SELECT 
         a.*, 
         rownum as row_num 
     FROM 
         (SELECT DISTINCT 
              lot.lot_no AS lotNo, lot.sel as sel,
              lot.C_ARRIVAL_NOTICE_NO AS arrNoticeNo,
              lot.C_SHIPMENT_DIRECTION AS shipmentDirection,
              lot.C_SENDERS_REFERENCE_NUM AS externalReference,
              lot.booking_seq AS bookingNo,lot.shipper AS shipperCode,
              nvl(lot.shipper_name ,lot.shipper_addr1) AS shipperName,
              NVL2 (lot.commdesc, lot.commdesc || ' ', '') || NVL2 (lot.comdesc1,lot. comdesc1 || ' ', '') || NVL2 (lot.comdesc2, lot.comdesc2 || ' ', '') || NVL2 (lot.comdesc3, lot.comdesc3 || ' ', '') || NVL2 (lot.comdesc4, lot.comdesc4 || ' ', '') || NVL2 (lot.comdesc5, lot.comdesc5 || ' ', '') || NVL2 (lot.comdesc6,lot. comdesc6 || ' ', '') || NVL2 (lot.comdesc7,lot. comdesc7 || ' ', '') || NVL2 (lot.comdesc8, lot.comdesc8 || ' ', '') || NVL2 (lot.comdesc9, lot.comdesc9, '') AS description,
              lot.lot_qty AS pieces, lot.lot_wght AS weight,
              lot.lot_cube AS cube,
              to_char(lot.input_date, 'dd-Mon-YYYY') AS lotDate,
              lot.e_m AS e_m, lot.warehouse AS warehouse,
              to_char(lot.in_date , 'dd-Mon-YYYY') AS inDate,
              lot.in_time AS inTime, lot.hold AS hold,
              to_char(lot.sail_date, 'dd-Mon-YYYY') AS sailDate,
              to_char(lot.sail_date, 'dd-Mon-YYYY') AS etdDate,
              lot.container AS container,
              lot.oml_bl_no AS billOfLadingNumber,
              lot.reference AS fileNumber,
              lot.inland_carrier AS trucker,
              lot.pro_number AS proNumber,
              lot.comments AS exceptions, lot.vessel AS vessel,
              lot.cstatus AS status, lot.voyage AS voyage, 
              (SELECT count(*) FROM tra_shipment_status 
                WHERE c_reference = lot.lot_no AND i_status_code = '857940') as transmitcount,
              (SELECT c_finalcfs_code FROM imp_bl_top 
                WHERE inv_no = lot.C_Arrival_Notice_No) as cfsCode, 
              'STI_COUNTRY_US' AS schemaName 
          FROM 
              itemdata lot 
          WHERE 
              lot.in_date BETWEEN TO_DATE('27-FEB-2017 00:00', 'DD-MON-YYYY HH24:MI') 
                              AND TO_DATE('29-MAR-2017 23:59', 'DD-MON-YYYY HH24:MI') 
              AND lot.sel IS NOT NULL 
              AND (lot.C_ARRIVAL_NOTICE_NO IS NOT NULL OR 
                   lot.C_SHIPMENT_DIRECTION ='IO') 
              AND lot.I_STATUS > 0 AND Lot.Cstatus = 'D' 
          ORDER BY 
              lot.lot_no desc, lot.in_date desc) a 
      WHERE 
          rownum <= 60) 
WHERE 
    row_num >= 1

0 个答案:

没有答案