oracle olap查询执行时间过长

时间:2015-04-11 08:01:25

标签: oracle performance olap sql-tuning

我有以下表格:

1)date_table_dim

2)clock_table_dim

3)onlinegpspoint:其中包含olap报告的主要信息

还有一个像这样的SQL查询:

SELECT 
  date_table_dim.day_id day_id,
  clock_table_dim.hour_id hour_id

FROM  onlinegpspoint olgps
INNER JOIN date_table_dim
ON ( 
olgps.occurance_time >= to_date('2014-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
AND olgps.occurance_time  >= date_table_dim.day_id
AND olgps.occurance_time   < date_table_dim.day_id + 1
)
INNER JOIN  clock_table_dim
ON ( clock_table_dim.hour_id <= TO_NUMBER(TO_CHAR(occurance_time, 'HH24'))
AND clock_table_dim.hour_id   > TO_NUMBER(TO_CHAR((occurance_time - 1/24), 'HH24') ))

GROUP BY 
  date_table_dim.day_id,
  clock_table_dim.hour_id ;

我的问题是这个查询执行时间太长。 可以采取哪些措施来提高查询执行的性能?

修改

onlinegpspoint上有一个占有时间的索引。通过这个查询,我想得到一些Olap信息1小时的时间。 (此查询是我的fact_table查询的一种摘要。)

1 个答案:

答案 0 :(得分:0)

您可以尝试以下查询。

SQLFiddle

with t as (select d.day_id, o.occurance_time ot
  from onlinegpspoint o
  join date_table_dim d on ( o.occurance_time >= date '2014-03-01'
    and d.day_id <= o.occurance_time and o.occurance_time < d.day_id + 1) ) 
select day_id, c.hour_id
  from t join clock_table_dim c on ( 
    c.hour_id <= to_char(t.ot, 'HH24') and to_char((t.ot - 1/24), 'HH24') < c.hour_id )
  group by day_id, c.hour_id order by day_id, c.hour_id;

在原始查询中,您将to_char(occurance_time, 'HH24')hour_id进行比较,此处索引可能不起作用。 因此,想法是首先将数据过滤到有趣的时期,然后仅使用这些过滤后的数据。


还有一个值得尝试的问题,这给了我很有希望的结果:

select distinct trunc(occurance_time) day_id, to_char(occurance_time, 'hh24')+0 hour_id 
  from onlinegpspoint o join (
    select to_date(to_char(day_id, 'yyyy-mm-dd ')||' '
        ||lpad(hour_id, 2, 0), 'yyyy-mm-dd hh24') dt 
      from date_table_dim, clock_table_dim) d 
    on (o.occurance_time >= date '2014-03-01' 
      and d.dt-1/24 <= o.occurance_time and o.occurance_time < d.dt)