之间需要更长的时间。调整SQL查询

时间:2016-11-11 08:16:34

标签: sql oracle query-performance

我有下面的查询,它需要花费很长的执行时间aprox 20分钟为一组行1345222.我有办法调整这个,特别是Between子句比较?

<code>
SELECT /*+ PARALLEL(32) */ upexp.item,
                  upexp.loc,
                  startdate,
                  sku_exp.bucket_size,
                  MAX(upexp.sku_multiplier) OVER (PARTITION BY upexp.item,upexp.loc) max_sm
                        FROM
                                (SELECT bucket bkt,
                                        MIN(dates) OVER (PARTITION BY bucket) minbk,
                                        MAX(dates)  OVER (PARTITION BY bucket) maxbk
                                FROM (
                                        SELECT LEVEL AS sl,
                                        NEXT_DAY (TRUNC (SYSDATE, 'YEAR') + 7 * LEVEL - 8,'SATURDAY') AS dates,
                                        CEIL (LEVEL/4) AS bucket
                                        FROM DUAL
                                        CONNECT BY LEVEL <= ((4 - MOD (78, 4) + 78) + 78)) yy
                               -- GROUP BY bucket
                                ) minmaxdate ,
                        stsc.u_promo_sku_expand sku_exp,
                        stsc.u_promo_upload_expand upexp
                        WHERE sku_exp.bucket_size = 4
                        AND sku_exp.startdate BETWEEN minmaxdate.minbk AND minmaxdate.maxbk
                        AND upexp.item = sku_exp.item
                        AND upexp.loc = sku_exp.loc
                        AND upexp.u_country = sku_exp.u_country
                        AND ((eff BETWEEN minmaxdate.minbk AND minmaxdate.maxbk+6)
                        OR ( disc BETWEEN minmaxdate.minbk AND minmaxdate.maxbk+6)
                        OR ( eff <= minmaxdate.minbk AND disc >= minmaxdate.maxbk+6))

</code>

1 个答案:

答案 0 :(得分:0)

此块

jquery

似乎没用,因为你只需要最小值和最大值。

试试这个:

(SELECT bucket bkt,
   MIN(dates) OVER (PARTITION BY bucket) minbk,
   MAX(dates)  OVER (PARTITION BY bucket) maxbk
FROM (
     SELECT LEVEL AS sl,
         NEXT_DAY (TRUNC (SYSDATE, 'YEAR') + 7 * LEVEL - 8,'SATURDAY') AS dates,
         CEIL (LEVEL/4) AS bucket
     FROM DUAL
     CONNECT BY LEVEL <= ((4 - MOD (78, 4) + 78) + 78)) yy
     -- GROUP BY bucket
     )