已是最简了不过按执行速度来说'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);
'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);
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')
TAB 表中有大概17678127 数据,我不知道你这个表,一共有多少列?,一共占用的多大空间?
看你这个数据量,我感觉主要是IO读取好耗性能了,不知道你这个表,有没有优化,
例如:做分区表
如果你这个导出不是很常用的话,就忍忍吧!
如果你这个表常用的话,做数据库的优化吧,SQL语句的优化,已经很难了