一、监控方式:
1、使用IP地址登录英克批发系统管理员角色(业务服务器、定时器服务器、接口服务器各取一台监控即可)
(1)定时器服务器地址:172.31.20.149:8090
(2)应用服务器地址:172.31.20.142:8090-172.31.20.146:8090
(3)接口服务器地址:172.31.20.147:8090-172.31.20.148:8090
2、打开”112服务器事务查询界面”
3、点击启用监控-查询按钮
4、根据本次查询结果,取出用时排名前20位的事务(连接池为备库的事务除外),针对细单中单条执行超过0.1秒的SQL进行后续相关优化操作
5、执行时间为:每周周一至周五;上午10:00-11:00;下午16:00-17:00
6、注意事项:
(1)查询没问题了就清空记录;
(2)监控结束及时关闭监控;
(3)系统会自动回收。
7、记录方式:【腾讯文档】性能工作清单
https://docs.qq.com/sheet/DQktMYmxhbVNualN1

二、优化方式:
1、SQL优化(具体可咨询核心业务部数据库负责人:谭磊)
(1)减少访问数据库的次数
   当执行每条SQL语句时,Oracle在内部执行许多工作:解析SQL语句,估算索引的利用率,绑定变量,读数据块等。因此,减少访问数据库的次数,能实际减少Oracle的工作量。 即一个SQL能完成的事,就不要写多个SQL。

(2)引用是一个方便的方法,但这是一个非常低效的方法。实际上,Oracle在解析的过程中,会将依次转换成所有的列名,这个工作是通过查询数据字典完成的,这以为这将耗费更多的时间。即SELECT语句中避免使用*
低效SQL:select * from rs_dept;
高效SQL:select dept_id,dept_code,dept_name from rs_dept;

(3)用where子句替换having子句
  避免使用HAVING子句,HAVING只会在检索出所有记录之后才对结果集进行过滤,这个处理需要排序总计等操作。如果通过WHERE子句限制记录的数目,那就能减少这方面的开销。
  HAVING中的条件一般用于对一些集合函数的比较,如COUNT()等,除此之外,一般的条件放入WHERE子句中。
低效SQL:select e.deptno,avg(nvl(e.sal,0)) from emp e
group by dtptno
having deptno!=201 and deptno!=203
高效SQL:select e.deptno,avg(nvl(e.sal,0)) from emp e
where deptno!=201 and deptno!=203
group by deptno

(4)减少对表的查询
  在含有子查询的SQL语句中,要特别注意减少对表的查询。
低效SQL:select empno from emp
where ename=(select ename from emp1 where sta=1)
and tag=(select tag from emp1 where sta=1)
高效SQL:select empno from emp
where (ename,tag)=(select ename,tag,from emp1 where sta=1)

(5) 用exists代替in
  在许多基于基础表的查询中,为了满足一个条件,往往需要对另一个表进行联接。在这种情况下,使用exists(或not exists)通常将提高查询的效率。
低效SQL:select * from emp where empno>0
and deptno in (select deptno from dept where loc=’M’)
高效SQL:select * from emp e where e.empno>0
and exists (select 1 from dept d where e.deptno=d.deptno and loc=’M’)

(6)用not exists代替not in
  用子查询时,not in子句将执行一个内部的排序和合并。无论在哪种情况下,not in都是最低效的(因为它对子查询中的表执行了一个全表遍历)。为了避免使用not in,我们可以把它改写成外连接或not exists。
低效SQL:select * from emp where deptno not in (select deptno from dept hwhere dept_cat=’A’)
高效SQL:select * from emp e
where not exists (select 1 from dept d where d.deptno=e.deptno an dept_cat=’A’)

(7)避免在索引列上使用计算或函数
  WHERE子句中,如果索引列是函数的一部分,优化器将不适用索引而使用全表扫描
低效SQL:select * from emp where sal*12>25000
高效SQL:select * from emp where sal>25000/12

(8)用UNION代替OR
  通常情况下,用UNION代替WHERE子句中的OR将会起到较好的效果。对索引列使用OR将造成全表扫描。注意,以上规则只针对多个索引列有效。如果COLUMN没有被索引,查询效率没有OR好。
低效SQL:select * from locations where loc_id=10 or region=’mm’
高效SQL:
select * from locations where loc_id=10
union
select * from locations where region=’mm’

(9)避免在索引列上使用 IS NULL和 IS NOT NULL
  避免在索引中使用任何可以为空的列,Oracle将无法使用该索引。对于单列索引,如果列包含空值,索引中将不存在此记录。对于复合索引,如果每个列都为空,索引中同样不存在此记录。如果至少有一个列不为空,则记录存在于索引中。
低效SQL:select * from emp where empcode is not null
高效SQL:select * from emp where empcode>=0

(10)带通配符(%)的like语句
  通配符(%)在搜寻首出现时,优化器是不会使用索引的,而是进行全表查询。
低效SQL:select * from emp where last_name like ‘%Beill%’
高效SQL:select * from emp where last_name like ‘Beill%’

(11) 用exists代替distinct
  当提交一个包含一对多信息(比如部门表和雇员表)的查询时,避免在select子句中使用distinct,一般可以考虑用exists替换。
低效SQL:select distinct deptno,deptname from emp e,dept d where d.deptno=e.deptno
高效SQL:select deptno,deptname from dept d
where exists (select 1 from emp e where e.deptno=d.deptno)

2、代码优化(具体可咨询核心业务部开发负责人:秦学波)
(1)开发时避免使用视图嵌套视图的方式

(2)尽量避免使用动态SQL
  动态SQL失去了编译期检查能力,将发生问题的可能性推迟到运行期。动态SQL也不利于优化,因为只有在运行期才能得到完整的SQL语句。

3、方案优化(具体可咨询核心业务部方案负责人:刘春燕)
(1)采用多级查询的方式实现用户业务目标

(2)限制用户查询的最长时间

文档更新时间: 2023-12-22 10:04   作者:胡校胤