0

I'm trying to cope with data densification for reporting purposes. I created two dimension tables (time & skills) and one data table (calls). Now since during certain time there are no calls in the data table, I will not get a time series including all the days. I now have studied many samples in the Internet how to cope with data densification and came up the the solution below.

Query works as intended, just it takes quite long and I have the feeling it is quite inefficient. Could you please advice me how to speed up query execution time?

Thank you and best regards, Alex

SELECT DISTINCT
  DAY_ID,
  DAY_SHORT,
  WEEK_ID,
  MONTH_ID,
  QUARTER_ID,
  YEAR_ID,
  AREA,
  FIRMA,
  PRODUCT,
  PRODUCT_FAMILY,
  PRODUCT_WFM,
  LANGUAGE,
  NVL(NCO,0) NCO,
  NVL(NCH,0) NCH,
  NVL(NCH60,0) NCH60,
  NVL(LOST,0) LOST
FROM (
  SELECT
    DS.AREA,
    DS.FIRMA,
    DS.PRODUCT,
    DS.PRODUCT_FAMILY,
    DS.PRODUCT_WFM,
    DS.LANGUAGE,
    SUM(NVL(CH.HANDLED,0)+NVL(CH.LOST,0)) AS NCO,
    SUM(CH.HANDLED) AS NCH,
    SUM(CH.HANDLED_IN_SL) AS NCH60,
    SUM(CH.LOST) AS LOST,
    CH.DELIVER_DATE,
    CH.SKILL_NAME
  FROM
    WFM.WFM_TBL_DIMENSION_SKILL DS
  LEFT JOIN
    OPS.VW_CALL_HISTORY CH
  ON
    DS.SPLIT_NAME=CH.SKILL_NAME
  GROUP BY
    DS.AREA,
    DS.FIRMA,
    DS.PRODUCT,
    DS.PRODUCT_FAMILY,
    DS.PRODUCT_WFM,
    DS.LANGUAGE,
    CH.DELIVER_DATE,
    CH.SKILL_NAME
) temp_values
PARTITION BY
(
  temp_values.AREA,
  temp_values.FIRMA,
  temp_values.PRODUCT,
  temp_values.PRODUCT_FAMILY,
  temp_values.PRODUCT_WFM,
  temp_values.LANGUAGE,
  temp_values.DELIVER_DATE,
  temp_values.SKILL_NAME
)
RIGHT OUTER JOIN (
  SELECT
    DAY_ID,
    DAY_SHORT,
    WEEK_ID,
    MONTH_ID,
    QUARTER_ID,
    YEAR_ID
  FROM
    WFM.WFM_TBL_DIMENSION_TIME
  WHERE
    DAY_ID BETWEEN(SELECT MIN(DELIVER_DATE) FROM OPS.VW_CALL_HISTORY) and TRUNC(sysdate-1)
) temp_time
ON
  temp_values.DELIVER_DATE=temp_time.DAY_ID
4

2 回答 2

0

我将参数简化PARTITION BY () 为单个主键 (temp_values.SKILL_NAME),并将技能维度中缺少的信息与LEFT OUTER JOIN上述查询末尾的 a 连接起来。这样就不会产生更多相等的重复,这导致我 reduce SELECT DISTINCT to SELECT

此外,我添加了外键和主键,并让查询以并行模式运行。

它帮助我将执行时间减少了 80% 以上,这已经足够了。多谢你们!

于 2012-05-16T14:51:21.557 回答
0

查看执行计划并检查哪些步骤需要很长时间。用来EXPLAIN PLAN获取。寻找全表扫描,看看索引是否有帮助。确保您在表格上有最新的统计数据。
由于您在谈论维度表,因此假定此代码来自数据仓库数据库。如果是,您是否使用分区?并行 DML?你用的是EE吗?

于 2012-05-16T02:26:33.057 回答