【赛迪网-it技术报道】最近很长一段时间都在优化一个项目,这个项目存在许多问题,从数据架构到工作流
程,我一直在思考一些有关oracle性能优化的问题,我跟开发实施人员进行过多次交流,
发现存在许多交流障碍,许多问题实施人员觉得sql语句执行很快,并不存在性能问题,
我花了大量时间要他看执行计划,说明当数据积累到一定时间后,会执行越来越慢。
我举一个例子来说明问题:
select v2.*
from consultationrecorddoctor t1
right outer join
(select cr.*, crc.modifydate, crc.modifyuserid, crc.consultationtime,
crc.applyconsultationdeptid, crc.askconsultationdeptid,
crc.consultationdeptid, crc.casehistory_right,
crc.consultationorder_right, crc.consultationidea_right,
crc.otherhospital_right, crc.consultationdate,
crc.maindoctorid, c1.deptname_vchr as applydeptname,
c2.deptname_vchr as askdeptname,
c3.deptname_vchr as deptname,
f_getempnamebyno (crc.maindoctorid) as maindocname
from consultationrecord cr,
consultationrecordcontent crc,
t_bse_deptdesc c1,
t_bse_deptdesc c2,
t_bse_deptdesc c3,
(select cr.inpatientid, cr.inpatientdate, cr.opendate,
cr.createdate,
max (crc.modifydate) as maxmodifydate
from consultationrecord cr,
consultationrecordcontent crc
where (crc.applyconsultationdeptid = '0000208')
and cr.inpatientid = crc.inpatientid
and cr.inpatientdate = crc.inpatientdate
and cr.opendate = crc.opendate
and cr.status = 0
group by cr.inpatientid,
cr.inpatientdate,
cr.opendate,
cr.createdate) v1
where (crc.applyconsultationdeptid = '0000208')
and cr.inpatientid = crc.inpatientid
and cr.inpatientdate = crc.inpatientdate
and cr.opendate = crc.opendate
and cr.status = 0
and crc.applyconsultationdeptid = c1.deptid_chr
and crc.askconsultationdeptid = c2.deptid_chr
and crc.consultationdeptid = c3.deptid_chr
and cr.inpatientid = v1.inpatientid
and cr.inpatientdate = v1.inpatientdate
and cr.opendate = v1.opendate
and v1.maxmodifydate = crc.modifydate
and crc.maindoctorid is not null) v2
on t1.inpatientid = v2.inpatientid
and t1.inpatientdate = v2.inpatientdate
and t1.opendate = v2.opendate
and t1.modifydate = v2.modifydate
and t1.employeeflag = 1
where t1.employeeid is null
order by t1.employeeid desc, v2.askdeptname, v2.consultationdate;
查询使用了一个右连接,查询的表并没有包含t1表的字段,而且在实际的t1.employeeid中
根本不存在null的值,实际上是从一个大的结果集剔除一个大结果集的而获得一个小的结
果集,随着crc表数据量加大,会越来越慢!
闽公网安备 35060202000074号