你好,游客 登录 注册 搜索
背景:
阅读新闻

记一次Oracle Sql优化经历--消耗过多CPU

[日期:2012-02-17] 来源:Linux社区  作者:csucxcc [字体:大 中 小]

常规的gc cr multi block request等待事件,没有看到比较异常的等待。老办法,制作ash看看

根据当前时间做ash报告。
SQL> @$Oracle_HOME/rdbms/admin/ashrpt.sql
Current Instance
~~~~~~~~~~~~~~~~
   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 4193910433 WBDB                1 wbdb1

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type:
Type Specified:  html

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
  4193910433        2 WBDB         wbdb2        fjlt_wb_db02
* 4193910433        1 WBDB         wbdb1        fjlt_wb_db01

Defaults to current database
Using database id: 4193910433
Defaults to current instance
Using instance number: 1
ASH Samples in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Oldest ASH sample available:  05-Feb-12 23:00:09   [  10995 mins in the past]
Latest ASH sample available:  13-Feb-12 14:14:45   [      0 mins in the past]

Specify the timeframe to generate the ASH report
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter begin time for report:

--    Valid input formats:
--      To specify absolute begin time:
--        [MM/DD[/YY]] HH24:MI[:SS]
--        Examples: 02/23/03 14:30:15
--                  02/23 14:30:15
--                  14:30:15
--                  14:30
--      To specify relative begin time: (start with '-' sign)
--        -[HH24:]MI
--        Examples: -1:15  (SYSDATE - 1 Hr 15 Mins)
--                  -25    (SYSDATE - 25 Mins)

Defaults to -15 mins
Enter value for begin_time: 02/13/12 10:00:00
Report begin time specified: 02/13/12 10:00:00

Enter duration in minutes starting from begin time:
Defaults to SYSDATE - begin_time
Press Enter to analyze till current time
Enter value for duration:02/13/12 10:30:00

以下输出省略
Enter value for report_name: wbdb01_ash_20120213_1000_1030
以下输出省略
打开生成好的ash报告
                      

从上图可以看到CPU资源的竞争才是真正的问题。
      

根据上图 sqlid 为 dczhdxppd0fmm 的 sql 占用了41.4 的活动时间

完整 sql 如下

select a.shbxhm, nvl(sum(a.ylbx_jfjs), 0) from t_wb_shbxmxsbb a, t_wb_sbbqk b where a.pz_xh = b.pz_xh and a.swglm = :1 and to_char(a.sfssq_qsrq, 'yyyy-mm-dd') = :2 and to_char(a.sfssq_zzrq, 'yyyy-mm-dd') = :3 and b.zt in ('2', '4', '5', '6') group by a.shbxhm

查看该 sql 的执行计划             

这里需要加上相应的用户

SQL> explain plan for select a.shbxhm, nvl(sum(a.ylbx_jfjs), 0) from ETAX. t_wb_shbxmxsbb a, ETAX .t_wb_sbbqk b where a.pz_xh = b.pz_xh and a.swglm = :1 and to_char(a.sfssq_qsrq, 'yyyy-mm-dd') = :2 and to_char(a.sfssq_zzrq, 'yyyy-mm-dd') = :3 and b.zt in ('2', '4', '5', '6') group by a.shbxhm;

Explained.

 

SQL> select * from table(DBMS_XPLAN.display)

 

PLAN_TABLE_OUTPUT

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Plan hash value: 2119216066

 

------------------------------------------------------------------------------------------------

| Id  | Operation                     | Name           | Rows  | Bytes | Cost (%CPU)| Time     |

------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT              |                |     1 |    86 | 35939   (1)| 00:07:12 |

|   1 |  HASH GROUP BY                |                |     1 |    86 | 35939   (1)| 00:07:12 |

|   2 |   NESTED LOOPS                |                 |     1 |    86 | 35938   (1)| 00:07:12 |

|*  3 |    TABLE ACCESS FULL          | T_WB_SHBXMXSBB |     1 |    67 | 35936   (1)| 00:07:12 |

|*  4 |    TABLE ACCESS BY INDEX ROWID| T_WB_SBBQK     |     1 |    19 |     2   (0)| 00:00:01 |

|*  5 |     INDEX UNIQUE SCAN         | PK_T_WB_SBBQK  |     1 |       |     1   (0)| 00:00:01 |

 

PLAN_TABLE_OUTPUT

---------------------------------------------------------------------------------------------------------------------------------

 

Predicate Information (identified by operation id):

---------------------------------------------------

 

   3 - filter("A"."SWGLM"=TO_NUMBER(:1) AND

              TO_CHAR(INTERNAL_FUNCTION("A"."SFSSQ_QSRQ"),'yyyy-mm-dd')=:2 AND

              TO_CHAR(INTERNAL_FUNCTION("A"."SFSSQ_ZZRQ"),'yyyy-mm-dd')=:3)

   4 - filter("B"."ZT"='2' OR "B"."ZT"='4' OR "B"."ZT"='5' OR "B"."ZT"='6')

   5 - access("A"."PZ_XH"="B"."PZ_XH")

 

21 rows selected.

linux
相关资讯       oracle数据库教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款