有以下SQL,执行速度慢,15秒才能执行完成:
select attrvalue,groupname,count(taskid) as totalCount,SUM(flag) as failnum
from simu_dnsAll
where simulator.get_date_from_millisecond(tm) between to_date('2010-06-14', 'yyyy-mm-dd') and to_date('2010-06-20', 'yyyy-mm-dd')
group by attrvalue, groupname;
simu_dnsAll是视图:
create or replace view simu_dnsall as
select t1.taskid,t1.groupname,t2.timeconsuming,t3.attrvalue,
decode(t2.timeconsuming,185,'1',decode((185-t2.timeconsuming)/abs(185-t2.timeconsuming),1,'0','1')) flag,
t2.generatedtime tm
from monitor_task t1, monitor_response t2,monitor_attr_config t3
where (t1.groupname = 'DNS拨测-长沙80' or t1.groupname = 'DNS拨测-长沙81' or t1.groupname = 'DNS拨测-衡阳231' or t1.groupname = 'DNS拨测-衡阳232')
and t1.taskid = t2.taskid
and t1.taskid = t3.taskid
and t3.attrname = 'query'
order by tm desc
解决过程:create index idx_timeconsu on monitor_response(timeconsuming)
还是不走索引。
原因是如果在列上建索引,在函数中用的话是不走索引的
最后把 to_date('2010-06-14', 'yyyy-mm-dd') 转换成和tm相同的数据格式
修改成:
select attrvalue,groupname,count(taskid) as totalCount,SUM(flag) as failnum
from simu_dnsAll
where tm between (1276444800000 ) and
(1276963200000)
group by attrvalue, groupname
这样就会使用tm上的索引。
或者是simulator.get_date_from_millisecond这个function中的return 数据类型 子句后面加上一个 deterministic限定词
阅读(711) | 评论(0) | 转发(0) |