查看SQL执行计划的方法及优劣

本文介绍了在Oracle数据库中查看SQL执行计划的各种方法,包括AWR报告、Explain Plan for、DBMS_XPLAN.display_cursor、DBMS_XPLAN.display_awr以及Autotrace的不同用法和优缺点。这些工具可以帮助数据库管理员和开发者深入理解SQL的执行性能,进行有效的性能优化。
摘要由CSDN通过智能技术生成

640?wx_fmt=gif&wxfrom=5&wx_lazy=1&retryload=1


作者 | 胡佳伟:云和恩墨技术工程师,有多年数据库优化经验,在一线执行过多个包括通信、保险等行业的优化项目。


在 Oracle 的性能分析中,很多时候需要对 SQL 进行分析,而最重要的就是对执行计划的分析。在本次的分享中,我主要介绍常用的查看 SQL 执行计划的方法。


1 AWR SQL report


AWR 报告是对数据库性能诊断最常用的方式,同时 AWR SQL report 是展示AWR 负载信息中记录的关于 SQL 的相关信息的报告。


AWR SQL report 使用的脚本为 $ORACLE_HOME/rdbms/admin/awrsqrpt.sql、awrsqrpi.sql。通常使用的脚本为 awrsqrpt.sql,该脚本可生成 SQL 在 AWR 信息内保存的执行计划等信息。而 awrsqrpi.sql 可以配合 awr 信息的导出与导入的功能,在被导入的库中生成相关的 AWR 报告。导入与导出的脚本同样在如上的路径里,为 awrextr、awrload,本次不进行演示。


使用方法:


与 AWR 报告生成方法一样,首先登陆数据库:


[oracle@localhost data]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed May 2 09:45:30 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Conneced to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 

SQL> @?/rdbms/admin/awrsqrpt

Current Instance

~~~~~~~~~~~~~~~~

   DB Id    DB Name Inst Num Instance

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

  231940243 H 1 h     -----当前的数据库

Specify the Report Type

~~~~~~~~~~~~~~~~~~~~~~~

Would you like an HTML report, or a plain text report?

Enter 'html' for an HTML report, or 'text' for plain text

Defaults to 'html'

Enter value for report_type:   -----选择报告的格式(通常选择默认HTML)

Instances in this Workload Repository schema

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   DB Id     Inst Num DB Name   Instance Host

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

* 231940243    1 H   h localhost.lo     ----生成报告的数据库

caldomain

  4026143893    1 NETDB   netdb1 ywdb1

  3391174693    1 FWPTDB   fwptdb1 fwptdb01

  4026143893    2 NETDB   netdb2 ywdb2

  3391174693    2 FWPTDB   fwptdb2 fwptdb02

Using  231940243 for database Id

Using       1 for instance number

Specify the number of days of snapshots to choose from

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Entering the number of days (n) will result in the most recent

(n) days of snapshots being listed.  Pressing <return> without

specifying a number lists all completed snapshots.

Enter value for num_days:    -----列出N天前到现在的SNAP_SHOT

Listing the last 2 days of Completed Snapshots

Snap

Instance     DB Name    Snap Id    Snap Started    Level

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

h     H 233 02 May 2018 09:45   1

234 02 May 2018 11:00   1

235 02 May 2018 12:00   1

236 02 May 2018 13:00   1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值