已是最简了不过按执行速度来说'i_0603',
'i_0617',
'i_0616',
'i_0627',
'i_0709',
'i_0717',
'i_0723',
'i_724z'
这个放入一个临时表中,假设为t,然后在tab表的time列建个临时索引,t表的enterflag建个索引最后执行
select distinct phone from tab l
where time >= to_date('2012-06-01', 'yyyy-mm-dd')
and time < to_date('2012-08-01', 'yyyy-mm-dd')
and exists (select 1 from t where t.enterflag=l.enterflag);

解决方案 »

  1.   

    今天按照一楼的方法,建立了,看执行成本,没有很大变化。反而多了一个连接的select 1 from t where t.enterflag=l.enterflag 成本
      

  2.   


    select distinct phone from tab l
    where to_char(time,'yyyy-mm) in('2012-06','2012-07')
    and l.enterflag in ('i_0603',
    'i_0617',
    'i_0616',
    'i_0627',
    'i_0709',
    'i_0717',
    'i_0723',
    'i_724z')
      

  3.   

    这个我不推荐,压根就没有理解EXISTS与IN的区别,像这种情况,用LZ的这种性能已经很高了。
    TAB 表中有大概17678127 数据,我不知道你这个表,一共有多少列?,一共占用的多大空间?
    看你这个数据量,我感觉主要是IO读取好耗性能了,不知道你这个表,有没有优化,
    例如:做分区表
    如果你这个导出不是很常用的话,就忍忍吧!
    如果你这个表常用的话,做数据库的优化吧,SQL语句的优化,已经很难了
      

  4.   

    这个表有四列,在phone上建了索引。。现在看来只能做数据库优化,没有做分区。。