Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43315
  • 博文数量: 5
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 64
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-08 22:01
文章分类

全部博文(5)

文章存档

2015年(3)

2013年(2)

我的朋友

分类: Oracle

2015-06-29 17:07:57



今天某开发同事说生产系统打开表单时很慢很慢,特意向我请教!

因为他那边生产系统很严格,所以只能在他的仿真系统上搞!

首先让他打开他说响应很慢的那个界面,然后运行以下语句:

点击(此处)折叠或打开

  1. select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
  2.   from v$session a, v$sqlarea b
  3. where a.sql_address = b.address ;
ok,捉到SQL语句了!



点击(此处)折叠或打开

  1. select workitemhi0_.DBID as DBID22_,
  2.        workitemhi0_.ID_FLOWPROCESS as ID2_22_,
  3.        workitemhi0_.ID_ROOTFLOWPROCESS as ID3_22_,
  4.        workitemhi0_.ID_EXECUTION as ID4_22_,
  5.        workitemhi0_.ID_TASK as ID5_22_,
  6.        workitemhi0_.ID_SOURCETASK as ID6_22_,
  7.        workitemhi0_.ID_SOURCEWORKITEM as ID7_22_,
  8.        workitemhi0_.FROMACTIVITYID as FROMACTI8_22_,
  9.        workitemhi0_.FROMACTIVITYNAME as FROMACTI9_22_,
  10.        workitemhi0_.ACTIVITYID as ACTIVITYID22_,
  11.        workitemhi0_.ACTIVITYNAME as ACTIVIT11_22_,
  12.        workitemhi0_.STATEINT as STATEINT22_,
  13.        workitemhi0_.SEQUENCENUM as SEQUENC13_22_,
  14.        workitemhi0_.CREATEDTIME as CREATED14_22_,
  15.        workitemhi0_.STARTEDTIME as STARTED15_22_,
  16.        workitemhi0_.VISITEDTIME as VISITED16_22_,
  17.        workitemhi0_.ENDEDTIME as ENDEDTIME22_,
  18.        workitemhi0_.USERID as USERID22_,
  19.        workitemhi0_.USERNAME as USERNAME22_,
  20.        workitemhi0_.ORGANCOMBINEDCODE as ORGANCO20_22_,
  21.        workitemhi0_.ORGANFULLNAME as ORGANFU21_22_,
  22.        workitemhi0_.MAPPINGUNITFULLNAME as MAPPING22_22_,
  23.        workitemhi0_.AGENTID as AGENTID22_,
  24.        workitemhi0_.AGENTNAME as AGENTNAME22_,
  25.        workitemhi0_.AGENTORGANCOMBINEDCODE as AGENTOR25_22_,
  26.        workitemhi0_.AGENTORGANFULLNAME as AGENTOR26_22_,
  27.        workitemhi0_.SYSID as SYSID22_,
  28.        workitemhi0_.SYSNAME as SYSNAME22_,
  29.        workitemhi0_.URLEVELINT as URLEVELINT22_,
  30.        workitemhi0_.TODOLABEL as TODOLABEL22_,
  31.        workitemhi0_.TODOTIP as TODOTIP22_,
  32.        workitemhi0_.SENDERID as SENDERID22_,
  33.        workitemhi0_.SENDERNAME as SENDERNAME22_,
  34.        workitemhi0_.SENDERORGANCOMBINEDCODE as SENDERO34_22_,
  35.        workitemhi0_.SENDERORGANFULLNAME as SENDERO35_22_,
  36.        workitemhi0_.SENDAGENTID as SENDAGE36_22_,
  37.        workitemhi0_.SENDAGENTNAME as SENDAGE37_22_,
  38.        workitemhi0_.SENDAGENTORGANCOMBINEDCODE as SENDAGE38_22_,
  39.        workitemhi0_.SENDAGENTORGANFULLNAME as SENDAGE39_22_,
  40.        workitemhi0_.SENDOPTIONID as SENDOPT40_22_,
  41.        workitemhi0_.DELPRETODOINT as DELPRET41_22_,
  42.        workitemhi0_.KEEPTODO as KEEPTODO22_,
  43.        workitemhi0_.SENDEMINT as SENDEMINT22_,
  44.        workitemhi0_.SENDIMINT as SENDIMINT22_,
  45.        workitemhi0_.SENDSMINT as SENDSMINT22_,
  46.        workitemhi0_.SENDPMINT as SENDPMINT22_,
  47.        workitemhi0_.STEPID as STEPID22_,
  48.        workitemhi0_.STEPNAME as STEPNAME22_,
  49.        workitemhi0_.FIRSTVISITTIME as FIRSTVI49_22_
  50.   from T_WORKITEM_HIST workitemhi0_
  51.  where workitemhi0_.ID_ROOTFLOWPROCESS = :1
  52.    and workitemhi0_.STATEINT = :2
  53.    and (workitemhi0_.USERID in ('U=1653459/O=03020001'))
  54.  order by workitemhi0_.CREATEDTIME


然后,用PL/SQL看了一下他的执行计划,原来T_WORKITEM_HIST是走的全表扫描!

再看看这个表的条数:有385W左右,尼玛,坑爹的,生产至少是这个数的1000(业务决定的),所以可想而知全表扫描的后果了!

接下来,我们优化这个SQL,很简单的, 单表的优化,无非就是没有正确的索引!

仔细一看,建立这个样的组合索引


点击(此处)折叠或打开

  1. create index idx_No0629 on T_WORKITEM_HIST(ID_ROOTFLOWPROCESS,STATEINT,USERID)

然后再看看执行计划,秒出!

然后在生产中建立此索引,速度至少比之前快了上百倍!



阅读(2310) | 评论(0) | 转发(0) |
0

上一篇:MongoDB 选择片键时应该考虑的问题

下一篇:没有了

给主人留下些什么吧!~~