Oracle查询时间优化

时间:2016-07-15 14:48:15

标签: sql oracle optimization

如何优化查询时间(超过1小时)?我只能访问表视图,无法检查查询计划和查看索引。我只能更改查询表示法。表'c'已经有超过32亿条记录。

SELECT
a.APPLICATIONNUMBER,c.NEWSTATUSSYMBOL,c.MODDATE,c.NEXT_MODDATE
FROM a
LEFT JOIN 
(SELECT
c000.ID,c000.NEWSTATUSSYMBOL,c000.MODDATE,c000.NEXT_MODDATE
FROM
(SELECT
c00.ID,c00.NEWSTATUSSYMBOL,c00.MODDATE,LEAD(c00.MODDATE,1) OVER (ORDER BY c00.ID, c00.MODDATE) AS NEXT_MODDATE
FROM
(SELECT
c0.ID,c0.STATUSSYMBOL,c0.NEWSTATUSSYMBOL,c0.MODDATE
FROM c0
WHERE (c0.STATUSSYMBOL in ('State1','State2','State3') OR c0.NEWSTATUSSYMBOL in ('State1','State2','State3'))                                                                    
AND c0.TYPEID = 1
AND c0.HDB_START >= '15/01/01'
AND c0.HDB_LAST      = 'Y')c00
)c000
WHERE
c000.NEWSTATUSSYMBOL in ('State1','State2','State3')) c
ON a.ID = c.ID

WHERE
a.APPLICATIONNUMBER like 'P%'
AND a.APPLICATIONSTATUSSYMBOL in ('State4','State5','State6')
AND a.APPLICATIONDATE           >= to_timestamp('2015-01-01 00:00:01')
AND a.MODIFIEDDATE >= to_timestamp('2016-07-04 00:00:01')
AND a.MODIFIEDDATE <= to_timestamp('2016-07-10 23:59:59')
AND a.HDB_LAST                 = 'Y';

1 个答案:

答案 0 :(得分:0)

在这里猜一点。如上所述没有你猜测的查询计划和索引,我没有你的表或数据。但查询是否在同一查询下面?看起来他们是2个桌子你外面加入co和a是正确的吗?咕咕声和抄袭是co的问题吗?所以你能否反对co一次?

WITH t1
     AS (SELECT ID,
                STATUSSYMBOL,
                NEWSTATUSSYMBOL,
                MODDATE
           FROM c0
          WHERE     TYPEID = 1
                AND HDB_START >= '15/01/01'
                AND HDB_LAST = 'Y'
                AND (   STATUSSYMBOL IN ('State1', 'State2', 'State3')
                     OR NEWSTATUSSYMBOL IN ('State1', 'State2', 'State3'))),
     t2
     AS (SELECT APPLICATIONNUMBER, ID
           FROM a
          WHERE     a.APPLICATIONNUMBER LIKE 'P%'
                AND a.APPLICATIONSTATUSSYMBOL IN ('State4',
                                                  'State5',
                                                  'State6')
                AND a.APPLICATIONDATE >= TO_TIMESTAMP ('2015-01-01 00:00:01')
                AND a.MODIFIEDDATE >= TO_TIMESTAMP ('2016-07-04 00:00:01')
                AND a.MODIFIEDDATE <= TO_TIMESTAMP ('2016-07-10 23:59:59')
                AND a.HDB_LAST = 'Y')
SELECT t2.APPLICATIONNUMBER,
       t1.NEWSTATUSSYMBOL,
       t1.MODDATE,
       LEAD (t1.MODDATE, 1) OVER (ORDER BY t1.ID) AS NEXT_MODDATE
  FROM t1 LEFT JOIN t2 ON t1.ID = t2.ID