码迷,mamicode.com
首页 > 数据库 > 详细

数据库性能优化

时间:2018-12-20 15:40:46      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:影响   性能   关联   method   信息   like   dex   创建   过滤   

多个表关联的sql语句,如果某个关联的表只取个别字段,则子查询效率比表关联高一些。

以下的子查询取部门和职位的描述的写法,比直接关联部门和职位表取描述的效率高一些。

WITH TMP AS
(SELECT B.EMPLID,
B.EMPL_RCD,
B.setid_dept,
B.DEPTID,
B.HR_STATUS,
B.BUSINESS_UNIT,
B.POSITION_NBR,
B.EFFDT
FROM PS_JOB B
WHERE B.EFFDT = (SELECT MAX(B_ED.EFFDT)
FROM PS_JOB B_ED
WHERE B_ED.EMPLID = B.EMPLID
AND B_ED.EMPL_RCD = B.EMPL_RCD)
AND B.EFFSEQ = (SELECT MAX(B_ES.EFFSEQ)
FROM PS_JOB B_ES
WHERE B_ES.EMPLID = B.EMPLID
AND B_ES.EMPL_RCD = B.EMPL_RCD
AND B_ES.EFFDT = B.EFFDT))
SELECT SEC.OPRID,
A.EMPLID,
B.EMPL_RCD,
A.NAME,
A.NAME_AC,
B.HR_STATUS,
B.BUSINESS_UNIT,
B.DEPTID,
(SELECT C.DESCR
FROM PS_DEPT_TBL C
WHERE C.EFFDT = (SELECT MAX(EFFDT)
FROM PS_DEPT_TBL C_ED
WHERE B.SETID_DEPT = C.SETID
AND B.DEPTID = C.DEPTID
AND C_ED.SETID = C.SETID
AND C_ED.DEPTID = C.DEPTID
AND C_ED.EFFDT <= B.EFFDT)),
B.POSITION_NBR,
(SELECT D.DESCR
FROM PS_POSITION_DATA D
WHERE D.EFFDT = (SELECT MAX(EFFDT)
FROM PS_POSITION_DATA D_ED
WHERE B.POSITION_NBR = D.POSITION_NBR
AND D_ED.POSITION_NBR = D.POSITION_NBR
AND D_ED.EFFDT <= B.EFFDT))
FROM PS_EMPLMT_SRCF_QRY SEC, PS_NAMES A, TMP B
WHERE SEC.EMPLID = B.EMPLID
/* and b.emplid=‘20130581‘*/
AND SEC.EMPL_RCD = B.EMPL_RCD
AND A.EMPLID = B.EMPLID
AND SEC.OPRID = ‘PS‘
and a.NAME LIKE ‘郭伟丽%‘

PLSQL 查看执行计划

一般来说正常的优化器逻辑是先过滤数据(filter)然后再关联

 

 

 

 

 

 

 

 

 

 

统计信息更新会对执行效率有一定的影响

BEGIN
DBMS_STATS.GATHER_TABLE_STATS(ESTIMATE_PERCENT => DBMS_STATS.AUTO_SAMPLE_SIZE,
ownname => ‘SYSADM‘,
tabname => ‘PS_JOB‘,
METHOD_OPT => ‘for all indexed columns‘,
DEGREE => DBMS_STATS.DEFAULT_DEGREE,
CASCADE => TRUE);
END;

 

 

创建序号用Oracle NEXTVAL 

:
SQLExec("SELECT TRANSACTION_NBR.NEXTVAL FROM DUAL", &returnValue);
:
CREATE SEQUENCE "SYSADM"."TRANSACTION_NBR" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;

 

数据库性能优化

标签:影响   性能   关联   method   信息   like   dex   创建   过滤   

原文地址:https://www.cnblogs.com/binquan/p/10149228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!