当数据积累到一定时间后执行会越来越慢

网络整理 - 07-26

最近很长一段时间都在优化一个项目,这个项目存在许多问题,从数据架构到工作流程,我一直在思考一些有关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表数据量加大,会越来越慢!