返回顶部
首页 > 资讯 > 数据库 >Oracle中怎么获取SQL执行计划
  • 692
分享到

Oracle中怎么获取SQL执行计划

2024-04-02 19:04:59 692人浏览 独家记忆
摘要

这篇文章将为大家详细讲解有关oracle中怎么获取sql执行计划,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Oracle 获取SQL执行计划方法方法一:D

这篇文章将为大家详细讲解有关oracle中怎么获取sql执行计划,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

Oracle 获取SQL执行计划方法

方法一:DBMS_XPLAN.DISPLAY_CURSOR 
方法二:explain plan for ......
方法三:Tuning SQL*Plus(autotrace)
方法四:*+ gather_plan_statistics *
方法五:10046
方法六: 10053
方法七:awrsqrpt.sql 
方法八:statistics_level=all

方法一:DBMS_XPLAN.DISPLAY_CURSOR 


(1)从共享池里获取
SELECT * FROM TABLE(dbms_xplan.display_cursor('SQL_ID'));

By default, the table function DISPLAY_CURSOR formats the execution plan for the last SQL statement executed by the session.

DISPLAY_CURSOR Function
This table function displays the explain plan of any cursor loaded in the cursor cache. 
In addition to the explain plan, various plan statistics (such as. I/O, memory and timing) can be reported (based on the V$SQL_PLAN_STATISTICS_ALL VIEWS).

Syntax

DBMS_XPLAN.DISPLAY_CURSOR(
   sql_id           IN  VARCHAR2  DEFAULT  NULL,
   cursor_child_no  IN  NUMBER    DEFAULT  0, 
   format           IN  VARCHAR2  DEFAULT  'TYPICAL');

Example:

SYS@orcl> SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno); 
14 rows selected.

SYS@orcl> SELECT sql_id, child_number FROM v$sql WHERE sql_text LIKE '%TOTO%';  
--9dpnjdgna1k40            

SYS@orcl> SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR('9dpnjdgna1k40',0));
SQL_ID  9dpnjdgna1k40, child number 0
-------------------------------------
SELECT  ename, dname   FROM scott.dept d   join scott.emp e
USING (deptno)

Plan hash value: 844388907

----------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         |       |       |     6 (100)|          |
|   1 |  MERGE JOIN                  |         |    14 |   308 |     6  (17)| 00:00:01 |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00:00:01 |
|*  4 |   SORT JOIN                  |         |    14 |   126 |     4  (25)| 00:00:01 |
|   5 |    TABLE ACCESS FULL         | EMP     |    14 |   126 |     3   (0)| 00:00:01 |
----------------------------------------------------------------------------------------

Predicate InfORMation (identified by operation id):
---------------------------------------------------

   4 - access("D"."DEPTNO"="E"."DEPTNO")
       filter("D"."DEPTNO"="E"."DEPTNO")

24 rows selected.

或者直接查询:
SELECT t.* FROM v$sql s, table(DBMS_XPLAN.DISPLAY_CURSOR(s.sql_id, s.child_number)) t WHERE sql_text LIKE '%TOTO%';

优点: 
(1)知道sql_id就可以得到执行计划,和explain plan for一样无须执行;
(2)可以得到真实执行计划;
缺点:
(1)没有输出运行时的相关统计信息(例如:逻辑读,递归调用次数,物理读等)
(2)无法判断处理多少上;
(3)无法判断表访问多少次; 
适用:
一个SQL对应多个执行计划; 

方法二: explain plan for获取


(1)EXPLAIN PLAN FOR XXX;
(2)select * from table(DBMS_XPLAN.DISPLAY);
(3)从awr性能视图里获取
SELECT * FROM TABLE(dbms_xplan.display_awr('SQL_ID'));

DISPLAY Function
This table function displays the contents of the plan table.

In addition, you can use this table function to display any plan (with or without statistics) stored in a table as long as the columns of this table are named the same as columns of the plan table (or V$SQL_PLAN_STATISTICS_ALL if statistics are included).
You can apply a predicate on the specified table to select rows of the plan to display.

Syntax

DBMS_XPLAN.DISPLAY(
   table_name    IN  VARCHAR2  DEFAULT 'PLAN_TABLE',
   statement_id  IN  VARCHAR2  DEFAULT  NULL, 
   format        IN  VARCHAR2  DEFAULT  'TYPICAL',
   filter_preds  IN  VARCHAR2 DEFAULT NULL);
   
Example:
(1)EXPLAIN PLAN FOR XXX;
(2)select * from table(DBMS_XPLAN.DISPLAY);

SYS@orcl> 
EXPLAIN PLAN FOR
SELECT *
  FROM scott.emp e, scott.dept d
 WHERE e.deptno = d.deptno
   AND e.ename = 'CLARK';  
Explained.

SYS@orcl> SET LINESIZE 130
SYS@orcl> SET PAGESIZE 0
SYS@orcl> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
Plan hash value: 3625962092

----------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         |     1 |    58 |     4   (0)| 00:00:01 |
|   1 |  NESTED LOOPS                |         |       |       |            |          |
|   2 |   NESTED LOOPS               |         |     1 |    58 |     4   (0)| 00:00:01 |
|*  3 |    TABLE ACCESS FULL         | EMP     |     1 |    38 |     3   (0)| 00:00:01 |
|*  4 |    INDEX UNIQUE SCAN         | PK_DEPT |     1 |       |     0   (0)| 00:00:01 |
|   5 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     1 |    20 |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - filter("E"."ENAME"='CLARK')
   4 - access("E"."DEPTNO"="D"."DEPTNO")

18 rows selected.

---如果执行计划下方出现'PLAN_TABLE' is old version提示,需要重新生成plan_table;
SQL> drop table PLAN_TABLE;
SQL> @?/rdbms/admin/utlxplan.sql

优点:
(1)无需真正的执行,快捷方便;
缺点:
(1)没有输出运行时的相关统计信息
(产生多少逻辑读,多少次递归调用,多少次物理读等情况)
(2)无法判断处理多少行;
(3)无法判断表被访问多少次;

适用于:
SQL执行很长时间才出结果或返回不了结果;

方法三:Tuning SQL*Plus(autotrace)


Tracing Statements
You can automatically get a report on the execution path used by the SQL optimizer and the statement execution statistics. The report is generated after successful SQL DML (that is, SELECT, DELETE, UPDATE and INSERT) statements. It is useful for monitoring and tuning the performance of these statements.

SQL*Plus report output may differ for DML if dynamic sampling is in effect.

Controlling the Autotrace Report
You can control the report by setting the AUTOTRACE system variable.
(1)SET AUTOTRACE OFF:
No AUTOTRACE report is generated. This is the default.
(2)SET AUTOTRACE ON EXPLAIN:
The AUTOTRACE report shows only the optimizer execution path
(3)SET AUTOTRACE ON STATISTICS:
The AUTOTRACE report shows only the SQL statement execution statistics.
(4)SET AUTOTRACE ON:
The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.
(5)SET AUTOTRACE TRACEONLY:
Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any. 
If STATISTICS is enabled, query data is still fetched, but not printed.

To use this feature, you must create a PLAN_TABLE table in your schema and then have the PLUSTRACE role granted to you. 
DBA privileges are required to grant the PLUSTRACE role.
(1)Creating a PLAN_TABLE
CONNECT HR 
@$ORACLE_HOME/rdbms/admin/utlxplan.sql 
(2)Creating the PLUSTRACE Role
CONNECT / AS SYSDBA 
@$ORACLE_HOME/sqlplus/admin/plustrce.sql 
(3)Granting the PLUSTRACE Role
CONNECT / AS SYSDBA 
GRANT PLUSTRACE TO HR; 

Example:

SYS@orcl> set autotrace on
SYS@orcl> 
SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno); 
 
......
14 rows selected.

Execution Plan
----------------------------------------------------------
Plan hash value: 844388907

----------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         |    14 |   308 |     6  (17)| 00:00:01 |
|   1 |  MERGE JOIN                  |         |    14 |   308 |     6  (17)| 00:00:01 |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00:00:01 |
|*  4 |   SORT JOIN                  |         |    14 |   126 |     4  (25)| 00:00:01 |
|   5 |    TABLE ACCESS FULL         | EMP     |    14 |   126 |     3   (0)| 00:00:01 |
----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("D"."DEPTNO"="E"."DEPTNO")
       filter("D"."DEPTNO"="E"."DEPTNO")Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          7  consistent gets
          0  physical reads
          0  redo size
        819  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         14  rows processed

报错SP2-0618需要执行plustrce.sql
SQL> conn scott/tiger
SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report

SQL> @?/sqlplus/admin/plustrce.sql
SQL> grant plustrace to scott;

优点: 
(1)可以输出运行时的相关统计信息(产生多少逻辑读,多少次递归调用,多少次物理读)
(2)traceonly可以控制返回结果不输出;
缺点: 
(1)必须等到语句真正执行完毕后,才可以出结果;
(2)无法看到表被访问多少次;

方法四:*+ gather_plan_statistics *


SYS@orcl> set linesize 130
SYS@orcl> show parameter statistics_level
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
statistics_level                     string      TYPICAL

SYS@orcl> SELECT
 ename, dname
  FROM scott.dept d
  join scott.emp e
 USING (deptno);  

......
14 rows selected.

SYS@orcl> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
SQL_ID  4y8f4mhhn471d, child number 0
-------------------------------------
SELECT  ename, dname   FROM scott.dept d
 join scott.emp e  USING (deptno)

Plan hash value: 844388907

-----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         |      1 |        |     14 |00:00:00.01 |       7 |       |       |          |PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
|   1 |  MERGE JOIN                  |         |      1 |     14 |     14 |00:00:00.01 |       7 |       |       |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |      1 |      4 |      4 |00:00:00.01 |       4 |       |       |          |
|   3 |    INDEX FULL SCAN           | PK_DEPT |      1 |      4 |      4 |00:00:00.01 |       2 |       |       |          |
|*  4 |   SORT JOIN                  |         |      4 |     14 |     14 |00:00:00.01 |       3 |  2048 |  2048 | 2048  (0)|
|   5 |    TABLE ACCESS FULL         | EMP     |      1 |     14 |     14 |00:00:00.01 |       3 |       |       |          |
-----------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("D"."DEPTNO"="E"."DEPTNO")PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
       filter("D"."DEPTNO"="E"."DEPTNO")

24 rows selected.

(1)starts为该SQL执行的次数;
(2)E-Rows为执行计划预计的行数;
(3)A-Rows为实际返回的行数。A-Rows和E-Rows做比较,就可以确定哪一步执行计划出了问题。
(4)A-Time为每一步实际执行的时间(HH:MM:SS.FF),根据这一行可以知道该SQL耗时在哪个地方;
(5)buffers为每一步实际执行的逻辑读或一致性读;
(6)Reads为物理读;

优点:

(1)可以清晰的从STARTS得出表被访问多少次;
(2)可以清晰的从E-ROWS和A-ROWS中得到预测的行数和真实的行数,从而可以准确判断Oracle评估是否准确;
(3)BUFFER显示真实的逻辑读数量;
缺点:
(1)必须要等到语句真正执行完毕后,才能出结果;
(2)无法控制记录不打屏输出,没有类似autotrace的traceonly的功能;
(3)看不出递归调用的次数,看不出物理读;

适用:
获取表被访问的次数;

方法五:10046


(1)
设置追踪标识符
alter session set tracefile_identifier='10046';
开启跟踪
alter session set events '10046 trace name context forever, level 12';
执行语句
select count(*) from all_objects;
关闭10046追踪
alter session set events '10046 trace name context off';

(2)
oradebug setmypid;
oradebug unlimit;
oradebug event 10046 trace name context forever ,level 12;
SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);
oradebug  tracefile_name;
Oradebug event 10046 trace name context off;

Example 1:

SYS@orcl> alter session set tracefile_identifier='10046';
SYS@orcl> alter session set events '10046 trace name context forever, level 12';
SYS@orcl> SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);
SYS@orcl> alter session set events '10046 trace name context off';
[oracle@uf2010813 trace]$ pwd     
/opt/oracle/app/diag/rdbms/orcl/orcl/trace

[oracle@uf2010813 trace]$ ll -rth *10046*
-rw-r-----. 1 oracle oinstall  135 Jul 31 21:55 orcl_ora_29418_10046.trm
-rw-r-----. 1 oracle oinstall 3.8K Jul 31 21:55 orcl_ora_29418_10046.trc

[oracle@uf2010813 trace]$ tkprof orcl_ora_29418_10046.trc 10046.log sys=no

Example 2:

SYS@orcl> oradebug setmypid;
SYS@orcl> oradebug unlimit;
SYS@orcl> oradebug event 10046 trace name context forever ,level 12;
SYS@orcl> SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);
SYS@orcl> oradebug  tracefile_name;
/opt/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_31388.trc

SYS@orcl> Oradebug event 10046 trace name context off;
[oracle@uf2010813 trace]$ tkprof orcl_ora_31388.trc 10046.log1 sys=no

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       4        0.00          0.00
  SQL*Net message from client                     4        6.17         17.25
  Disk file operations I/O                        2        0.00          0.00
  db file sequential read                         4        0.02          0.04
  
Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  Disk file operations I/O                        1        0.00          0.00
  db file sequential read                        23        0.01          0.12
  asynch descriptor resize                        1        0.00          0.00

    1  user  SQL statements in session.
   66  internal SQL statements in session.
   67  SQL statements in session.
********************************************************************************
Trace file: orcl_ora_31388.trc
Trace file compatibility: 11.1.0.7
Sort options: default

       1  session in tracefile.
       1  user  SQL statements in trace file.
      66  internal SQL statements in trace file.
      67  SQL statements in trace file.
      13  unique SQL statements in trace file.
    1390  lines in trace file.
       0  elapsed seconds in trace file.

优点:
(1)可以看出SQL语句对应的等待事件;
(2)如果SQL语句中有函数调用,函数中又有SQL,将会被列出;
(3)可以方便的看出处理的行数,产生的物理读,逻辑读;
(4)可以方便的看出解析时间和执行计划;
(5)可以跟踪整个程序包;
缺点: 
(1)步骤繁琐;
(2)无法判断表被访问多少次; 
(3)执行计划中谓词部分不能清晰展现出来;
适用:如果SQL中含函数,函数中又套SQL等,即存在多层调用,想准确分析只能用方法;

方法六:10053


(1)
alter session set tracefile_identifier='10053';
ALTER SESSION SET EVENTS='10053 trace name context forever, level 1';
select count(*) from dba_users;
ALTER SESSION SET EVENTS '10053 trace name context off';

(2)
oradebug  setmypid;
oradebug unlimit;
oradebug event 10053 trace name context forever, level 1;
SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);
oradebug  tracefile_name;
Oradebug event 10053 trace name context off;

Example 1:

SYS@orcl> alter session set tracefile_identifier='10053';
SYS@orcl> ALTER SESSION SET EVENTS='10053 trace name context forever, level 1';
SYS@orcl> select count(*) from dba_users;
SYS@orcl> ALTER SESSION SET EVENTS '10053 trace name context off';

[oracle@uf2010813 trace]$ ls -l *10053*
-rw-r-----. 1 oracle oinstall   566260 Aug  1 00:27 orcl_ora_13125_10053.trc
-rw-r-----. 1 oracle oinstall   119517 Aug  1 00:27 orcl_ora_13125_10053.trm

Example 2:

SYS@orcl> oradebug  setmypid;
SYS@orcl> oradebug unlimit;
SYS@orcl> oradebug event 10053 trace name context forever, level 1;
SYS@orcl> SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);
SYS@orcl> oradebug  tracefile_name;
/opt/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_11907_10053.trc
SYS@orcl> Oradebug event 10053 trace name context off;

方法七: awrsqrpt.sql 


(1)@?/rdbms/admin/awrsqrpt.sql
Type Specified:  html
Enter value for num_days: 1 
Enter value for begin_snap: 21034
Enter value for end_snap: 21035
Enter value for sql_id: 3ag4uwm6ypra1
Enter value for report_name: awrsqlrpt_0731.html

[oracle@uf2010813 ~]$ ls -l awrsqlrpt_0731.html 
-rw-r--r--. 1 oracle oinstall 13773 Aug  1 03:03 awrsqlrpt_0731.html

---Exec dbms_workload_repository.create_snapshot;
Oracle中怎么获取SQL执行计划
Oracle中怎么获取SQL执行计划
Oracle中怎么获取SQL执行计划
Oracle中怎么获取SQL执行计划

方法八: statistics_level=all 


(1)alter session set statistics_level=all; 
(2)执行SQL; 
(3)查看执行计划;
select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));

Example:

SYS@orcl> show parameter statistics_level
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
statistics_level                     string      TYPICAL

SYS@orcl> alter session set statistics_level=all;

SYS@orcl> set linesize 130
SYS@orcl>  SELECT ename, dname FROM scott.dept d join scott.emp e USING (deptno);  
SYS@orcl> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
SQL_ID  72zuupmcd922s, child number 0
-------------------------------------
 SELECT  ename, dname   FROM scott.dept d   join scott.emp e
 USING (deptno)

Plan hash value: 844388907

-----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         |      1 |        |     14 |00:00:00.01 |       7 |       |       |          |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
|   1 |  MERGE JOIN                  |         |      1 |     14 |     14 |00:00:00.01 |       7 |       |       |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |      1 |      4 |      4 |00:00:00.01 |       4 |       |       |          |
|   3 |    INDEX FULL SCAN           | PK_DEPT |      1 |      4 |      4 |00:00:00.01 |       2 |       |       |          |
|*  4 |   SORT JOIN                  |         |      4 |     14 |     14 |00:00:00.01 |       3 |  2048 |  2048 | 2048  (0)|
|   5 |    TABLE ACCESS FULL         | EMP     |      1 |     14 |     14 |00:00:00.01 |       3 |       |       |          |
-----------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("D"."DEPTNO"="E"."DEPTNO")

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
       filter("D"."DEPTNO"="E"."DEPTNO")24 rows selected.参考至:《循规蹈矩:快速读懂SQL执行计划的套路与工具》---梁敬彬
更多信息见官方文档:
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_xplan.htm#ARPLS378

DBMS_XPLAN

The DBMS_XPLAN package provides an easy way to display the output of the EXPLAIN PLAN command in several, predefined formats. You can also use the DBMS_XPLAN package to display the plan of a statement stored in the Automatic Workload Repository (AWR) or stored in a SQL tuning set. It further provides a way to display the SQL execution plan and SQL execution runtime statistics for cached SQL cursors based on the information stored in the V$SQL_PLAN and V$SQL_PLAN_STATISTICS_ALL fixed views. Finally, it displays plans from a SQL plan baseline.

Overview
The DBMS_XPLAN package supplies five table functions:
DISPLAY - to format and display the contents of a plan table.
DISPLAY_AWR - to format and display the contents of the execution plan of a stored SQL statement in the AWR.
DISPLAY_CURSOR - to format and display the contents of the execution plan of any loaded cursor.
DISPLAY_SQL_PLAN_BASELINE - to display one or more execution plans for the SQL statement identified by SQL handle
DISPLAY_SQLSET - to format and display the contents of the execution plan of statements stored in a SQL tuning set.

Http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_eight.htm#i1037231

Tuning SQL*Plus
SQL*Plus User's Guide and Reference

Statistics
The statistics are recorded by the server when your statement executes and indicate the system resources required to execute your statement. The results include the following statistics.
(1)recursive calls
Number of recursive calls generated at both the user and system level. Oracle Database maintains tables used for internal processing. When Oracle Database needs to make a change to these tables, it internally generates an internal SQL statement, which in turn generates a recursive call.
(2)db block gets
Number of times a CURRENT block was requested.
(3)consistent gets
Number of times a consistent read was requested for a block
(4)physical reads
Total number of data blocks read from disk. This number equals the value of "physical reads direct" plus all reads into buffer cache.
(5)redo size
Total amount of redo generated in bytes
(6)bytes sent through SQL*Net to client
Total number of bytes sent to the client from the foreground processes.
(7)bytes received through SQL*Net from client
Total number of bytes received from the client over Oracle Net.
(8)SQL*Net round-trips to/from client
Total number of Oracle Net messages sent to and received from the client
(9)sorts (memory)
Number of sort operations that were performed completely in memory and did not require any disk writes
(10)sorts (disk)
Number of sort operations that required at least one disk write
(11)rows processed
Number of rows processed during the operationSTATISTICS_LEVEL = { ALL | TYPICAL | BASIC }
STATISTICS_LEVEL specifies the level of collection for database and operating system statistics. The Oracle Database collects these statistics for a variety of purposes, including making self-management decisions.

The default setting of TYPICAL ensures collection of all major statistics required for database self-management functionality and provides best overall performance. The default value should be adequate for most environments.

When the STATISTICS_LEVEL parameter is set to ALL, additional statistics are added to the set of statistics collected with the TYPICAL setting. The additional statistics are timed OS statistics and plan execution statistics.

Setting the STATISTICS_LEVEL parameter to BASIC disables the collection of many of the important statistics required by Oracle Database features and functionality, including:

(1)Automatic Workload Repository (AWR) Snapshots
(2)Automatic Database Diagnostic Monitor (ADDM)
(3)All server-generated alerts
(4)Automatic SGA Memory Management
(5)Automatic optimizer statistics collection
(6)Object level statistics
(7)End to End Application Tracing (V$CLIENT_STATS)
(8)Database time distribution statistics (V$SESS_TIME_MODEL and V$SYS_TIME_MODEL)
(9)Service level statistics
(10)Buffer cache advisory
(11)MTTR advisory
(12)Shared pool sizing advisory
(13)Segment level statistics
(14)PGA Target advisory
(15)Timed statistics
(16)Monitoring of statistics

关于Oracle中怎么获取SQL执行计划就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

您可能感兴趣的文档:

--结束END--

本文标题: Oracle中怎么获取SQL执行计划

本文链接: https://lsjlt.com/news/57561.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Oracle中怎么获取SQL执行计划
    这篇文章将为大家详细讲解有关Oracle中怎么获取SQL执行计划,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Oracle 获取SQL执行计划方法方法一:D...
    99+
    2024-04-02
  • 执行计划-1:获取执行计划
    看懂执行计划是作为处理数据库性能问题的必备技能之一,接下来一系列的文章我 会告诉你怎么去做。 我们会从一些文章开始讨论几种获取执行计划的方法,并且评估不同来源的执行计划最适合哪种场景。 完成上述的内容后我...
    99+
    2024-04-02
  • Oracle获取执行计划方法
    获取执行计划的6种方法   1. explain plan for获取;   2. set autotrace on ;  &...
    99+
    2024-04-02
  • 获取oracle sql语句详细些执行计划
    获取oracle的SQL语句的执行有很多,比如使用plsql按F5,使用10046trace,使用set  autotrace on等方式查看SQL语句的执行计划。使用这种方式查看SQL语句的执...
    99+
    2024-04-02
  • SQLSERVER中如何获取执行计划
    SQLSERVER中如何获取执行计划,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。得到执行计划的方式有两种: 1、一种是在指令的...
    99+
    2024-04-02
  • oracle中怎么查看sql执行计划的执行顺序
    这篇文章主要讲解了“oracle中怎么查看sql执行计划的执行顺序”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“oracle中怎么查看sql执行计划的执行顺...
    99+
    2024-04-02
  • 怎么使用sql monitor获取更加详细的执行计划
    这篇文章主要讲解了“怎么使用sql monitor获取更加详细的执行计划”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用sql monitor获取更加...
    99+
    2024-04-02
  • oracle怎么查看sql历史执行计划
    要查看SQL历史执行计划,可以使用以下方法: 使用Oracle的动态性能视图:通过查询v$sql_plan或v$sql_plan_...
    99+
    2024-04-09
    oracle sql
  • mysql 获取执行计划的方法
    mysql 获取执行计划方法:1.通过explain进行查看sql的执行计划;2.通线程正在执行的sql查看该sql的执行计划; explain进行查看sql的执行计划相对简单,其实通线程正在执行的sq...
    99+
    2024-04-02
  • Oracle中怎么固定执行计划
    这篇文章给大家介绍Oracle中怎么固定执行计划,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。1.1  BLOG文档结构图 1.2  前言部分1.2.1 ...
    99+
    2024-04-02
  • oracle中怎么查看执行计划
    在Oracle中查看执行计划可以通过以下两种方法: 1、使用EXPLAIN PLAN语句来生成执行计划: EXPLAIN PLAN ...
    99+
    2024-03-13
    oracle
  • SQL Server中怎么执行计划缓存
    SQL Server中怎么执行计划缓存,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。基础概念SQL Server 有一个用于存储执行计划和数据...
    99+
    2024-04-02
  • Oracle Study--Oracle SQL执行计划查看(MindMap)
    Oracle Study--Oracle SQL执行计划查看(MindMap) ...
    99+
    2024-04-02
  • oracle怎么查看SQL执行计划的顺序
    本篇内容介绍了“oracle怎么查看SQL执行计划的顺序”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!查看...
    99+
    2024-04-02
  • 获取执行计划的6种方法
      一.获取执行计划的6种方法(详细步骤已经在每个例子的开头注释部分说明了):     1. explain plan for获取;   ...
    99+
    2024-04-02
  • MySQL 5.7获取指定线程正在执行SQL的执行计划信息
    获取指定线程正在执行SQL的执行计划信息,可以使用下面语句; 当某个线程执行SQL消耗了很长的时间,可以使用这个语句找到正在执行大SQL的执行计划,在性能诊断上很有用。 mysql> show pr...
    99+
    2024-04-02
  • Oracle固定SQL的执行计划(一)---SQL Profile
    我们都希望对于所有在Oracle数据库中执行的SQL,CBO都能产生出正确的执行计划,但实际情况却并非如此,由于各种各样的原因(比如目标SQL所涉及的对象的统计信息的不准确,或者CBO内部一些成本计算公式的...
    99+
    2024-04-02
  • Oracle怎么查看执行计划
    在Oracle数据库中,可以使用以下两种方法来查看执行计划: 1、使用EXPLAIN PLAN语句:您可以在SQL查询前添加”EXP...
    99+
    2024-04-09
    Oracle
  • oracle执行计划怎么创建
    oracle 执行计划创建方法:自动生成执行计划:通过 explain plan 命令查看 oracle 自动生成的计划。手动创建执行计划:通过创建索引、使用提示和调整优化器参数来手动指...
    99+
    2024-05-21
    oracle access
  • mysql怎么查看sql执行计划
    要查看MySQL中SQL语句的执行计划,可以使用EXPLAIN关键字来获取查询的执行计划。以下是使用EXPLAIN来查看SQL执行计...
    99+
    2024-04-15
    mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作