Chinaunix首页 | 论坛 | 博客
  • 博客访问: 455292
  • 博文数量: 97
  • 博客积分: 3396
  • 博客等级: 中校
  • 技术积分: 996
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-25 13:14
文章分类

全部博文(97)

文章存档

2014年(1)

2013年(2)

2012年(7)

2011年(13)

2010年(18)

2009年(7)

2007年(10)

2006年(39)

分类: Oracle

2010-07-16 17:04:26

有以下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限定词
阅读(682) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~