千万级数据SQL优化,急!!! 5
selectc.funid,count(c.funid)ascf,decode((Selectcount(t.userid)fromB_ANHUI_CLIENT_USE_...
select c.funid, count(c.funid) as cf , decode((Select count(t.userid)
from B_ANHUI_CLIENT_USE_DETAIL t join t_cust cust on trim(t.userid) = trim(cust.custid)
where funid = 'MDSP00001' and substr(t.createdate, 0, 10) >='2014-05-04' and '2014-05-04'>=substr(t.createdate, 0, 10)
and t.userid = '(null)'
Group By t.userid),Null, count(Distinct c.userid) ,(count(Distinct c.userid) + (Select count(t.userid)
from B_ANHUI_CLIENT_USE_DETAIL t join t_cust cust on trim(t.userid) = trim(cust.custid)
where funid = 'MDSP00001' and substr(t.createdate, 0, 10) >='2014-05-04' and '2014-05-04'>=substr(t.createdate, 0, 10)
and t.userid = '(null)'
Group By t.userid )- 1) )as cd
, Count(Distinct c.userid)As ck
from B_ANHUI_CLIENT_USE_DETAIL c
where
(to_date(substr(c.createdate, 0, 10), 'yyyy-mm-dd') >= to_date('2014-05-04','yyyy-mm-dd') and to_date('2014-05-04','yyyy-mm-dd')>=to_date(substr(c.createdate, 0, 10), 'yyyy-mm-dd') )
GROUP BY c.FUNID
函数用的太多没法建索引,建了函数索引也没效果,不知道是不是没走函数索引。现在这SQL执行完大概31秒,请高手优化!
不用了 ,解决了,建了个函数索引 速度变成0.4秒了 展开
from B_ANHUI_CLIENT_USE_DETAIL t join t_cust cust on trim(t.userid) = trim(cust.custid)
where funid = 'MDSP00001' and substr(t.createdate, 0, 10) >='2014-05-04' and '2014-05-04'>=substr(t.createdate, 0, 10)
and t.userid = '(null)'
Group By t.userid),Null, count(Distinct c.userid) ,(count(Distinct c.userid) + (Select count(t.userid)
from B_ANHUI_CLIENT_USE_DETAIL t join t_cust cust on trim(t.userid) = trim(cust.custid)
where funid = 'MDSP00001' and substr(t.createdate, 0, 10) >='2014-05-04' and '2014-05-04'>=substr(t.createdate, 0, 10)
and t.userid = '(null)'
Group By t.userid )- 1) )as cd
, Count(Distinct c.userid)As ck
from B_ANHUI_CLIENT_USE_DETAIL c
where
(to_date(substr(c.createdate, 0, 10), 'yyyy-mm-dd') >= to_date('2014-05-04','yyyy-mm-dd') and to_date('2014-05-04','yyyy-mm-dd')>=to_date(substr(c.createdate, 0, 10), 'yyyy-mm-dd') )
GROUP BY c.FUNID
函数用的太多没法建索引,建了函数索引也没效果,不知道是不是没走函数索引。现在这SQL执行完大概31秒,请高手优化!
不用了 ,解决了,建了个函数索引 速度变成0.4秒了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |