一个奇怪的sql查询问题
两个sql语句内容完全一样。 只是查询时间不一样。一个3秒就ok。 一个等了1分钟报错。
select count(*) from (
select d.outid,d.customerunitcode from rec_electtron_consume e inner join base_customers d on e.cardno=d.cardno and e.customerunitcode=d.customerunitcode where
e.buslineid=9999 and e.cardtype=34 and e.customerunitcode =
'08600000001' and e.uploaddate between to_date('2014-11-26','yyyy-mm-dd') and
to_date('2014-11-26','yyyy-mm-dd')+1 and cstaccfc<= 6175500) x inner join base_emp emp on x.outid=emp.outid and x.customerunitcode = emp.customerunitcode
11月26日的要等1分钟
select count(*) from (
select d.outid,d.customerunitcode from rec_electtron_consume e inner join base_customers d on e.cardno=d.cardno and e.customerunitcode=d.customerunitcode where
e.buslineid=9999 and e.cardtype=34 and e.customerunitcode =
'08600000001' and e.uploaddate between to_date('2014-11-25','yyyy-mm-dd') and
to_date('2014-11-25','yyyy-mm-dd')+1 and cstaccfc<= 6175500) x inner join base_emp emp on x.outid=emp.outid and x.customerunitcode = emp.customerunitcode
11月25日的3秒钟就ok了。
rec_electtron_consume 有6百万数据。
base_customers 有10万数据。
base_emp 有1万数据。
实际需要的数据有5000条左右。
但是就因为时间不一样, 差别很大。
本来想着是 rec_electtron_consume 数据有问题。 我 把rec_electtron_consume的buslineid=9999 的独立查出来放到另外一个表里。 有100万数据。 然后再来关联。 反而25号的也慢了。 再往前查 ,22号到25号的也慢。 21号以前的不慢。
问题很奇怪。 不知道往哪里查了? 请各位大神帮帮忙,给点建议。 100分散了。