a.calling_code
a.end_date
这两个列都创建索引

解决方案 »

  1.   

    "如果不加a.end_date > to_date('20031010'),速度很快,10秒搞定"
    那么肯定是索引起了反作用,改成
    select count(*) from tf_call a, tf_vip b
    where
    (a.calling_code = b.serv_code or a.called_code=b.serv_code)
    and trunc(a.end_date) > to_date('20031010','yyyymmdd');
      

  2.   

    alter table tf_call add paitition ADD PARTITION p1 VALUES LESS THAN(to_date('20011010','yyyymmdd');
    alter table tf_call add paitition ADD PARTITION p2 VALUES LESS THAN(to_date('20021010','yyyymmdd');
    alter table tf_call add paitition ADD PARTITION p3 VALUES LESS THAN(to_date('20031010','yyyymmdd'); 
    alter table tf_call add paitition ADD PARTITION p1 VALUES LESS THAN(to_date(MAXVALUE);  根本想改变sql性能,是从表结构做起,若tf_call一天可产生上万条记录,哪可用分区表方法.
    至于trunc(a.end_date)可以做一个函数索引
    create index ix_tf_call on tf_call(trunc(end_date));
      

  3.   

    我觉得有问题,我做过包含to_data函数的查询,时间上也就多个1、2倍。没有几个小时这么恐怖的。你试一下直接查询一个时间格式的相同的SQL语句看看。
      

  4.   

    你可以查一下此表占用的总空间数.如果此表曾经有100M,现在只有10M,用count(*)时将对100M空间进行查询而不是10M.这就是Oracle中所谓的Block Level(块水平位)方法1: truncate将回复水平位
    方法2: 使用count(字段名)而不是count(*),此处的字段名是一个有效索引列.最好在使用此索引前先rebuild