Oracle之SQL优化专题01-查看SQL执行计划的方法
在我2014年总结的“SQL Tuning 基础概述”中,其实已经介绍了一些查看SQL执行计划的方法,但是不够系统和全面,所以本次SQL优化专题,就首先要系统的介绍一下查看SQL执行计划的方法。
本文示例SQL为:
--set lines 1000 pages 1000
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
3.dbms_xplan
3.1 dbms_xplan.display_cursor(null,null,'allstats last')
3.2 dbms_xplan.display_cursor('&sql_id',null,'advanced')
3.3 dbms_xplan.display_awr('&sql_id')
1.explain plan for SQL;
通过explain plan for命令查看SQL的执行计划,这种方法SQL并不真实执行,一般适用于上线前的SQL预审,尤其对DML语句,由于SQL不执行,不用担心对生产数据造成影响。这种方法查看的执行计划有Predicate Information,无Statistics,查看到的执行计划不一定真实,第三方工具PL/SQL Developer中F5查看执行计划也是调用的这个方法。
使用explain plan for命令查看SQL的执行计划:
explain plan for
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
select * from table(dbms_xplan.display);
示例如下:
JINGYU@jyzhao1 >explain plan for
2 select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
Explained.
Elapsed: 00:00:00.01
JINGYU@jyzhao1 >select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 74 | 6 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Note
-----
- dynamic sampling used for this statement (level=2)
20 rows selected.
Elapsed: 00:00:00.03
JINGYU@jyzhao1 >
2.set autotrace
通过set autotrace查看SQL的执行计划,这种方法SQL真实执行(除set autot trace exp针对select语句也不执行,但对DML语句还是会执行的),这种方法查看的执行计划有Predicate Information,有Statistics,查看的执行计划是准确的(注意:如果SQL中包含有绑定变量,那么用该方法所获取到的执行计划,也有可能不是真实的)。但由于SQL需要真实执行,所以对于有绑定变量值的SQL,还需要输入对应的变量值才可以执行,比较麻烦。
使用set autotrace查看SQL的执行计划:
set autotrace on
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
set autotrace off
示例如下:
JINGYU@jyzhao1 >set autotrace on
JINGYU@jyzhao1 >select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
EMPNO ENAME DNAME JOB SAL
---------- ---------- -------------- --------- ----------
7788 SCOTT RESEARCH ANALYST 3000
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 74 | 6 (0)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
7 recursive calls
0 db block gets
15 consistent gets
0 physical reads
0 redo size
814 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
JINGYU@jyzhao1 >set autotrace off
JINGYU@jyzhao1 >
3.dbms_xplan
dbms_xplan下面有很多函数可以调用,其中最常用的是display_cursor和display_awr函数,下面依次介绍。
3.1 dbms_xplan.display_cursor(null,null,'allstats last')
通过dbms_xplan.display_cursor(null,null,'allstats last')查看SQL的执行计划,SQL会真实执行(对应的缺点不再赘述),这种方法查看的执行计划有Predicate Information,无Statistics,查看的执行计划是准确的,并且有每一步真实处理行数和时间。
使用dbms_xplan.display_cursor(null,null,'allstats last')查看SQL的执行计划:
--需要确认statistics_level设置为ALL,否则SQL语句第一个关键字后就需要加上/*+ gather_plan_statistics */,我习惯用前者
show parameter statistics_level(一般数据库默认是TYPICAL)
alter session set statistics_level = ALL;
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
示例如下:
JINGYU@jyzhao1 >alter session set statistics_level = ALL;
Session altered.
JINGYU@jyzhao1 >select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
EMPNO ENAME DNAME JOB SAL
---------- ---------- -------------- --------- ----------
7788 SCOTT RESEARCH ANALYST 3000
JINGYU@jyzhao1 >select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 39dv3d8jkzyuw, child number 1
-------------------------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
----------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 7 | | | |
|* 1 | HASH JOIN | | 1 | 1 | 1 |00:00:00.01 | 7 | 1214K| 1214K| 762K (0)|
|* 2 | TABLE ACCESS FULL| EMP | 1 | 1 | 1 |00:00:00.01 | 3 | | | |
| 3 | TABLE ACCESS FULL| DEPT | 1 | 4 | 4 |00:00:00.01 | 4 | | | |
----------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Note
-----
- dynamic sampling used for this statement (level=2)
26 rows selected.
JINGYU@jyzhao1 >
3.2 dbms_xplan.display_cursor('&sql_id',null,'advanced')
通过dbms_xplan.display_cursor('&sql_id',null,'advanced')查看SQL的执行计划,这种方法查看的执行计划有Predicate Information,无Statistics,SQL是数据库中之前真实执行过的,对应执行计划是之前SQL真实执行过的执行计划,是准确的。使用这种方法的前提是需要SQL的cursor没有被刷出shared pool,否则查不到结果。
使用dbms_xplan.display_cursor('&sql_id',null,'advanced')查看SQL的执行计划:
--查询sql_id
select sql_id, sql_text from v$sql where sql_text like 'select a.empno%';
39dv3d8jkzyuw
--根据查询的sql_id查看执行计划
select * from table(dbms_xplan.display_cursor('&sql_id',null,'advanced'));
--附:函数DISPLAY_CURSOR的参数说明
FUNCTION DISPLAY_CURSOR RETURNS DBMS_XPLAN_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_ID VARCHAR2 IN DEFAULT
CURSOR_CHILD_NO NUMBER(38) IN DEFAULT
FORMAT VARCHAR2 IN DEFAULT
示例如下:
JINGYU@jyzhao1 >select * from table(dbms_xplan.display_cursor('&sql_id',null,'advanced'));
Enter value for sql_id: 39dv3d8jkzyuw
old 1: select * from table(dbms_xplan.display_cursor('&sql_id',null,'advanced'))
new 1: select * from table(dbms_xplan.display_cursor('39dv3d8jkzyuw',null,'advanced'))
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID 39dv3d8jkzyuw, child number 0
-------------------------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
|* 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / A@SEL$1
3 - SEL$1 / B@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "A"@"SEL$1")
FULL(@"SEL$1" "B"@"SEL$1")
LEADING(@"SEL$1" "A"@"SEL$1" "B"@"SEL$1")
USE_HASH(@"SEL$1" "B"@"SEL$1")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=1) "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
2 - "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "A"."DEPTNO"[NUMBER,22]
3 - "B"."DEPTNO"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
Note
-----
- dynamic sampling used for this statement (level=2)
SQL_ID 39dv3d8jkzyuw, child number 1
-------------------------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
|* 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / A@SEL$1
3 - SEL$1 / B@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "A"@"SEL$1")
FULL(@"SEL$1" "B"@"SEL$1")
LEADING(@"SEL$1" "A"@"SEL$1" "B"@"SEL$1")
USE_HASH(@"SEL$1" "B"@"SEL$1")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=1) "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
2 - "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "A"."DEPTNO"[NUMBER,22]
3 - "B"."DEPTNO"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
Note
-----
- dynamic sampling used for this statement (level=2)
SQL_ID 39dv3d8jkzyuw, child number 2
-------------------------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
|* 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / A@SEL$1
3 - SEL$1 / B@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "A"@"SEL$1")
FULL(@"SEL$1" "B"@"SEL$1")
LEADING(@"SEL$1" "A"@"SEL$1" "B"@"SEL$1")
USE_HASH(@"SEL$1" "B"@"SEL$1")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
2 - filter("EMPNO"=7788)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=1) "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
2 - "EMPNO"[NUMBER,22], "A"."ENAME"[VARCHAR2,10],
"A"."JOB"[VARCHAR2,9], "A"."SAL"[NUMBER,22], "A"."DEPTNO"[NUMBER,22]
3 - "B"."DEPTNO"[NUMBER,22], "B"."DNAME"[VARCHAR2,14]
Note
-----
- dynamic sampling used for this statement (level=2)
177 rows selected.
JINGYU@jyzhao1 >
由于上面没有指定CURSOR_CHILD_NO,所以全部都会显示出来,当然也可以指定某个CURSOR_CHILD_NO,比如说:
select * from table(dbms_xplan.display_cursor('&sql_id',0,'advanced'));
这样结果就只会显示CURSOR_CHILD_NO=0的执行计划。
3.3 dbms_xplan.display_awr('&sql_id')
通过dbms_xplan.display_awr('&sql_id')查看SQL的执行计划,这种方法查看的执行计划无Predicate Information,无Statistics,查看的执行计划是准确的。如果对应SQL没有被抓取到AWR中,就查不到结果。
使用dbms_xplan.display_awr('&sql_id')查看SQL的执行计划:
--查询sql_id
39dv3d8jkzyuw
--根据查询的sql_id查看执行计划
select * from table(dbms_xplan.display_awr('&sql_id'));
--附:函数DISPLAY_AWR的参数说明
FUNCTION DISPLAY_AWR RETURNS DBMS_XPLAN_TYPE_TABLE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SQL_ID VARCHAR2 IN
PLAN_HASH_VALUE NUMBER(38) IN DEFAULT
DB_ID NUMBER(38) IN DEFAULT
FORMAT VARCHAR2 IN DEFAULT
示例如下:
JINGYU@jyzhao1 >select * from table(dbms_xplan.display_awr('&sql_id'));
Enter value for sql_id: 39dv3d8jkzyuw
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------
SQL_ID 39dv3d8jkzyuw
--------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
| 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
20 rows selected.
JINGYU@jyzhao1 >
也可以加参数显示更多的信息,比如可以显示出Outline Data,但没有Predicate Information,没有Statistics:
JINGYU@jyzhao1 >select * from table(dbms_xplan.display_awr('&sql_id',NULL,NULL,'advanced'));
Enter value for sql_id: 39dv3d8jkzyuw
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------
SQL_ID 39dv3d8jkzyuw
--------------------
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where
a.deptno = b.deptno and empno = 7788
Plan hash value: 1123238657
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 6 (100)| |
| 1 | HASH JOIN | | 1 | 74 | 6 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 1 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 88 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / A@SEL$1
3 - SEL$1 / B@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "A"@"SEL$1")
FULL(@"SEL$1" "B"@"SEL$1")
LEADING(@"SEL$1" "A"@"SEL$1" "B"@"SEL$1")
USE_HASH(@"SEL$1" "B"@"SEL$1")
END_OUTLINE_DATA
*/
Note
-----
- dynamic sampling used for this statement (level=2)
44 rows selected.
JINGYU@jyzhao1 >
4.awrsqrpt
通过awrsqrpt查看SQL的执行计划,这种方式是导出SQL的awr报告,这种方法查看的执行计划无Predicate Information,但有Statistics,并且同时包含SQL单次和整体的统计信息,查看的执行计划是准确的。
使用awrsqrpt查看SQL的执行计划:
@?/rdbms/admin/awrsqrpt
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 240
Begin Snapshot Id specified: 240
Enter value for end_snap: 244
End Snapshot Id specified: 244
Specify the SQL Id
~~~~~~~~~~~~~~~~~~
Enter value for sql_id: 39dv3d8jkzyuw
SQL ID specified: 39dv3d8jkzyuw
...
Report written to awrsqlrpt_1_240_244.html
这种执行计划的显示结果如下图:
5.10046 event
通过10046 event的跟踪文件查看SQL的执行计划,这种方法查看的执行计划是准确的,语句中函数,递归调用都会被详细列出,但没有谓词信息,而且这种方法获取执行计划比较麻烦。
使用10046 event查看SQL的执行计划:
alter session set events '10046 trace name context forever, level 12';
select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
alter session set events '10046 trace name context off';
--使用tkprof美化10046 event的跟踪文件,使其更易读:
tkprof jyzhao1_ora_14139.trc jyzhao1_ora_14139.txt sys=no
示例如下:
JINGYU@jyzhao1 >alter session set events '10046 trace name context forever, level 12';
Session altered.
JINGYU@jyzhao1 >select a.empno, a.ename, b.dname, a.job, a.sal from emp a, dept b where a.deptno = b.deptno and empno = 7788;
EMPNO ENAME DNAME JOB SAL
---------- ---------- -------------- --------- ----------
7788 SCOTT RESEARCH ANALYST 3000
JINGYU@jyzhao1 >alter session set events '10046 trace name context off';
Session altered.
--使用tkprof美化10046 event的跟踪文件相关内容如下:
SQL ID: 39dv3d8jkzyuw Plan Hash: 1123238657
select a.empno, a.ename, b.dname, a.job, a.sal
from
emp a, dept b where a.deptno = b.deptno and empno = 7788
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.02 0 8 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 7 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.01 0.02 0 15 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 91
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
1 1 1 HASH JOIN (cr=7 pr=0 pw=0 time=274 us cost=6 size=74 card=1)
1 1 1 TABLE ACCESS FULL EMP (cr=3 pr=0 pw=0 time=67 us cost=3 size=52 card=1)
4 4 4 TABLE ACCESS FULL DEPT (cr=4 pr=0 pw=0 time=15 us cost=3 size=88 card=4)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 6.55 6.56
********************************************************************************
关于阅读这个tkprof美化后文件的方法可以参考MOS文档:
- TKProf Interpretation (9i and above) (文档 ID 760786.1)
reference
关于这个“Oracle之SQL优化专题”的系列,缘起是听了公司SQL优化专家团队的分享内容,自己想通过实际操作理解并逐渐测试完善,在我个人之前的职业生涯规划中一直都偏重于运维方向的DBA,对SQL优化方面了解的很少,兴趣也不高,是SQL优化专家团队的这次分享让我觉得SQL优化也是很有趣的,所以下决心从今天起单独开一个专题,自己也能逐渐系统的学习相关知识并记录下来。初步考虑该系列后续内容同时还会参考崔华的《基于Oracle的SQL优化》一书。最后感谢SQL优化专家团队的leader勇哥和其团队所有成员,是你们的这次分享让我有了做这个专题的动力。
Oracle之SQL优化专题01-查看SQL执行计划的方法的更多相关文章
- Oracle之SQL优化专题02-稳固SQL执行计划的方法
首先构建一个简单的测试用例来实际演示: create table emp as select * from scott.emp; create table dept as select * from ...
- Oracle ->> Oracle下查看实际执行计划的方法
也许有很多种方法,这里只是书上学到的一种方法 with a as ( order by grp_factor) t ) select b.id, a.grp_factor )b --use v$sql ...
- Oracle之SQL优化专题03-如何看懂SQL的执行计划
专题第一篇<Oracle之SQL优化专题01-查看SQL执行计划的方法>讲到了查看SQL执行计划的方法,并介绍了各种方法的应用场景,那么这一篇就主要介绍下如何看懂SQL的执行计划.毕竟如果 ...
- 浅析SqlServer简单参数化模式下对sql语句自动参数化处理以及执行计划重用
我们知道,SqlServer执行sql语句的时候,有一步是对sql进行编译以生成执行计划, 在生成执行计划之前会去缓存中查找执行计划 如果执行计划缓存中有对应的执行计划缓存,那么SqlServer就会 ...
- SQL Sever 2008性能分析之执行计划
一直想找一些关于SQL语句性能调试的权威参考,但是有参考未必就能够做好调试 2的工作.我深信实践中得到的经验是最珍贵的,书本知识只是一个引导.本篇来源于<Inside Microsoft SQL ...
- SQL点滴27—性能分析之执行计划
原文:SQL点滴27-性能分析之执行计划 一直想找一些关于SQL语句性能调试的权威参考,但是有参考未必就能够做好调试的工作.我深信实践中得到的经验是最珍贵的,书本知识只是一个引导.本篇来源于<I ...
- 查看Mysql执行计划
使用navicat查看mysql执行计划: 打开profile分析工具: 查看是否生效:show variable like ‘%profil%’; 查看进程:show processlist; 选择 ...
- 如何查看MySQL执行计划
在介绍怎么查看MySQL执行计划前,我们先来看个后面会提到的名词解释: 覆盖索引: MySQL可以利用索引返回select列表中的字段,而不必根据索引再次读取数据文件 包含所有满足查询需要的数据的索引 ...
- SQL优化的一些总结 SQL编写一般要求
SQL编写一般要求---SQL语句尽可能简单---分解联接保证高并发---同数据类型的列值比较---不在索引列做运算---禁止使用SELECT *---避免负向查询和%前缀模糊查询---保持事务(连接 ...
随机推荐
- 浅谈Javascript中的Label语句
如: begin: for (var i = 0; i < 10 ; i++ ){ alert(i); } 举一个比较典型的例子,看完后即明白 Label 的应用:(未添加 Label) var ...
- 将nodejs代码部署到阿里云服务器
概述 最近在做一个小项目,其中用nodejs做了个数据转发的接口,之后需要将这部分代码部署到服务器上面,并使用Nginx做反向代理.期间使用搜索引擎大量查阅了其他同鞋的经验,不过写的大多很笼统,因此踩 ...
- Python机器学习 (Python Machine Learning 中文版 PDF)
Python机器学习介绍(Python Machine Learning 中文版) 机器学习,如今最令人振奋的计算机领域之一.看看那些大公司,Google.Facebook.Apple.Amazon早 ...
- 用vmware workstation制作cloudstack(kvm)镜像及问题解决办法
说明1:vmware workstation镜像是vmdk格式 说明2:cloudstack配置文件目录:/run/libvirt/qemu/ kvm配置文件目录:/etc/libvirt/q ...
- 今天给大家分享用Python matplotlib来写随机漫步的小程序
先安装两个库: pip install matplotlib pip install numpy 引用库: import matplotlib.pyplot as mp import numpy as ...
- Java Swing应用程序 JComboBox下拉框联动查询
在web项目中,通过下拉框.JQuery和ajax可以实现下拉框联动查询. 譬如说,当你查询某个地方时,页面上有:省份:<下拉框省份> 市区:<下拉框市区> 县乡:<下拉 ...
- SignalR Self Host+MVC等多端消息推送服务(4)
由于工作太忙,一直没时间更新博客,之前有很多朋友一直问我什么时候将后续的代码发上来,一直没时间,今天就长话短说,不写文章了,直接上demo,里面将正式项目中用到的一些敏感信息修改了,要使用的话下载后自 ...
- IntelliJ IDEA 源值1.5已过时,将在未来所有版本中删除
1. 修改Maven的Settings.xml文件添加如下内容 <profile> <id>jdk-1.8</id> <activation> < ...
- 在虚拟机VMware上安装Linux系统教程
目录: 一. CentOS的安装 二. RedHat的安装 三. VMwaretools的安装 此处提供CentOS和RedHat两个版本的系统安装流程,至于选哪个 ...
- Git分支(3/5) -- 禁用 Fast Forward 合并
添加一个分支, 并且换到该分支: git checkout -b add-text 然后我再index.html里面添加点文字, 并commit. 然后再修改README.md, 添加文字, comm ...