
oracle 查询的sql语句特别慢,是什么原因,是or特别慢吗,用什么优化,急急急!!!
selectc.costsno,c.coststype,e.empnofromcostsClaimsc,yjsemployeee,Departmentdt,project...
select c.costsno,
c.coststype,
e.empno
from costsClaims c,
yjsemployee e,
Department dt,
project p,
yjsmeeting m,
(select cd.costsno,
NVL(sum(cd.Vehicleamount), 0) vehicleamount,
from costsclaimdetail cd, costsclaims c
where c.company = 1000
and c.costsno = cd.costsno(+)
group by cd.costsno) cd,
(select ca.costsno, sum(nvl(ca.amount, 0)) amount
from cardsdetail ca, costsclaims co
where ca.company = 1000
and ca.coststype = 'T'
and co.costsno = ca.costsno(+)
group by ca.costsno) am
where c.empno = e.empno(+)
and c.deptno = dt.Deptno(+)
and c.allprojectno = p.projectno(+)
and c.meetingno = m.meetingno(+)
and c.costsno = cd.costsno(+)
and c.costsno = am.costsno(+)
and exists (select 'x'
from appuser tuser
where tuser.userid = c.createdby
and tuser.company = 1000)
and c.company = 1000
and c.createddate >= TO_DATE('2013-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
and c.createddate <= TO_DATE('2013-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
and ((c.createdby = 'liuqi' and c.state = 'return') or
(c.state = 'submit' and
(c.verfiedby = 'liuqi' or c.verfiedby = 'null')) or
c.state = 'verfied' or c.state = 'pass' or
c.state = 'passtwo' or c.state = 'passtwono' or
c.state = 'payamount' or c.state = 'payamounttwo' or
c.state = 'noinburse' or c.state = 'noinbursetwo')
and (c.coststype not in ('T', 'M'))
ORDER BY c.datesubmitted desc, c.costsno desc 展开
c.coststype,
e.empno
from costsClaims c,
yjsemployee e,
Department dt,
project p,
yjsmeeting m,
(select cd.costsno,
NVL(sum(cd.Vehicleamount), 0) vehicleamount,
from costsclaimdetail cd, costsclaims c
where c.company = 1000
and c.costsno = cd.costsno(+)
group by cd.costsno) cd,
(select ca.costsno, sum(nvl(ca.amount, 0)) amount
from cardsdetail ca, costsclaims co
where ca.company = 1000
and ca.coststype = 'T'
and co.costsno = ca.costsno(+)
group by ca.costsno) am
where c.empno = e.empno(+)
and c.deptno = dt.Deptno(+)
and c.allprojectno = p.projectno(+)
and c.meetingno = m.meetingno(+)
and c.costsno = cd.costsno(+)
and c.costsno = am.costsno(+)
and exists (select 'x'
from appuser tuser
where tuser.userid = c.createdby
and tuser.company = 1000)
and c.company = 1000
and c.createddate >= TO_DATE('2013-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
and c.createddate <= TO_DATE('2013-12-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss')
and ((c.createdby = 'liuqi' and c.state = 'return') or
(c.state = 'submit' and
(c.verfiedby = 'liuqi' or c.verfiedby = 'null')) or
c.state = 'verfied' or c.state = 'pass' or
c.state = 'passtwo' or c.state = 'passtwono' or
c.state = 'payamount' or c.state = 'payamounttwo' or
c.state = 'noinburse' or c.state = 'noinbursetwo')
and (c.coststype not in ('T', 'M'))
ORDER BY c.datesubmitted desc, c.costsno desc 展开
4个回答
展开全部
把查询计划的内容发出来,你这一大堆代码谁能看出来啥啊。看你的代码这么长,条件那么多,语句用了函数,很多低效的or,not in等操作,另外还用了group by,order by,左右连接等等,如果表数据量很大的话,你这个语句性能不好是预料中的事情。如果你这条语句无法优化,建议从调整表结构角度考虑
展开全部
(select cd.costsno,
NVL(sum(cd.Vehicleamount), 0) vehicleamount,
from costsclaimdetail cd, costsclaims c
where c.company = 1000
and c.costsno = cd.costsno(+)
group by cd.costsno) cd,
对这个子查询2个问题:
1、为啥这里要用左连接呢?难道cd与c里的costsno不一样多?
2、外边又有costsClaims c,而且还是 c.costsno = cd.costsno(+),你不觉得重复么?
建议不要这个子查询,直接在最外一层costsclaimdetail与costsclaims连接并group by
另1个子查询类似
exists (select 'x'
from appuser tuser
where tuser.userid = c.createdby
and tuser.company = 1000)
这个子查询可以改成costsClaims与appuser做连接
另外,不知道为什么这么多左连接,左连接比连接要慢
NVL(sum(cd.Vehicleamount), 0) vehicleamount,
from costsclaimdetail cd, costsclaims c
where c.company = 1000
and c.costsno = cd.costsno(+)
group by cd.costsno) cd,
对这个子查询2个问题:
1、为啥这里要用左连接呢?难道cd与c里的costsno不一样多?
2、外边又有costsClaims c,而且还是 c.costsno = cd.costsno(+),你不觉得重复么?
建议不要这个子查询,直接在最外一层costsclaimdetail与costsclaims连接并group by
另1个子查询类似
exists (select 'x'
from appuser tuser
where tuser.userid = c.createdby
and tuser.company = 1000)
这个子查询可以改成costsClaims与appuser做连接
另外,不知道为什么这么多左连接,左连接比连接要慢
更多追问追答
追问
那两个子查询是主要为了计算出金额。
(c.verfiedby = 'liuqi' or c.verfiedby = 'null')) or
c.state = 'verfied' .......省略..or c.state = 'noinbursetwo')
没有这一段话的数据是3000多条,还挺快,有这一段话的数据是500多条,非常慢
追答
那你把除了这个条件的做为一个子查询,然后对这个子查询做下这个where
不过costsclaimdetail与costsclaims还是多做一次left join,而且2个子查询算出来的值外面又没用,搞不懂
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这样查询应该慢吧,用连接查询看看,用连接查询代替子查询
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这么多子查询,那么多连接,能快么?看看能不能优化下写法吧,该建索引的建索引。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询