uction on 星期四 5月 21 13:09:27 2009
Copyright (c) 1982, 2005,
Oracle. All rights reserved.
SQL> conn ipra/acca@ipradev;
已连接
。 SQL> select count(*) from (select o.oatfna,o.oatprf,o.oatfrm,o.oattkt,o.oatcpn,o.oatpst,substr(u.ute
dsp,1,5) as errnum,o.oatcdt,o.oatcid from owbatn o,uplter u where (o.oatcer='Y' and o.oatcpn='0' and
u.utetkt=o.oattkt and u.rowid= (select max(rowid) from uplter where utetkt = o.oattkt and utefna=o
.oatfna)) or o.oatpst='D' or o.oatpst='I' or o.oatpst='F');
COUNT(*)
----------
17809
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 01nxqdvn71mx5, child number 0
-------------------------------------
select count(*) from (select o.oatfna,o.oatprf,o.oatfrm,o.oattkt,o.oatcpn,o.oatpst,substr(u.u
tedsp,1,5) as errnum,o.oatcdt,o.oatcid from owbatn o,uplter u where (o.oatcer='Y' and
o.oatcpn='0' and u.utetkt=o.oattkt and u.rowid= (select max(rowid) from uplter where utetkt
= o.oattkt and utefna=o.oatfna)) or o.oatpst='D' or o.oatpst='I' or o.oatpst='F')
Plan hash value: 2105702960
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3082 (100)| |
| 1 | SORT AGGREGATE | | 1 | 54 | | |
| 2 | CONCATENATION | | | | | |
| 3 | MERGE JOIN CARTESIAN | | 470K| 24M| 1969 (4)| 00:00:24 |
|* 4 | TABLE ACCESS FULL | OWBATN | 1 | 34 | 851 (5)| 00:00:11 |
| 5 | BUFFER SORT | | 316K| 6175K| 1118 (3)| 00:00:14 |
| 6 | TABLE ACCESS FULL | UPLTER | 316K| 6175K| 1118 (3)| 00:00:14 |
|* 7 | FILTER | | | | | |
|* 8 | HASH JOIN | | 37522 | 1978K| 1109 (6)| 00:00:14 |
|* 9 | TABLE ACCESS FULL | OWBATN | 20956 | 695K| 852 (5)| 00:00:11 |
| 10 | INDEX FAST FULL SCAN | IDX_UPLTER_UTETKT | 316K| 6175K| 246 (6)| 00:00:03 |
| 11 | SORT AGGREGATE | | 1 | 38 | | |
|* 12 | TABLE ACCESS BY INDEX ROWID| UPLTER | 1 | 38 | 4 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | IDX_UPLTER_UTETKT | 2 | | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(("O"."OATPST"='D' OR "O"."OATPST"='F' OR "O"."OATPST"='I'))
7 - filter("U".ROWID=)
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
8 - access("U"."UTETKT"="O"."OATTKT")
9 - filter(("O"."OATCPN"=0 AND "O"."OATCER"='Y' AND LNNVL("O"."OATPST"='I') AND
LNNVL("O"."OATPST"='F') AND LNNVL("O"."OATPST"='D')))
12 - filter("UTEFNA"=:B1)
13 - access("UTETKT"=:B1)
已选择39行
。 好了
,我们现在根据上述原则来解析一下上述执行计划的执行顺序。
先从最开头一直往右看
,直到看到最右边的并列的地方,对于不并列的,靠右的先执行:
从上述执行计划的开头一直往右看,直到找到最右边并列的。也就是从SELECT STATEMENT开始往右找,一直找到TABLE ACCESS FULL,这时候发现BUFFER SORT和它并列。
此时我们已经可以知道TABLE ACCESS FULL一定是比BUFFER SORT(包括其右边的所有语句)先执行,因为对于并列的,靠上的先执行。
而对于BUFFER SORT,它右边又有"TABLE ACCESS FULL | UPLTER",此时根据上述原则我们也可以知道,它比BUFFER SORT先执行。
这样对于上述执行计划里的这三条语句:
|* 4 | TABLE ACCESS FULL | OWBATN | 1 | 34 | 851 (5)| 00:00:11 |
| 5 | BUFFER SORT | | 316K| 6175K| 1118 (3)| 00:00:14 |
| 6 | TABLE ACCESS FULL | UPLTER | 316K| 6175K| 1118 (3)| 00:00:14 |
正确的执行顺序是:
先执行TABLE ACCESS FULL | OWBATN | 1 | 34 | 851 (5)| 00:00:11 |
再执行TABLE ACCESS FULL | UPLTER | 316K| 6175K| 1118 (3)| 00:00:14 |
最后执行BUFFER SORT | | 316K| 6175K| 1118 (3)| 00:00:14 |
这样我们就解析出来了最内层上述三条语句的执行顺序,然后我们再应用上述原则解析其外层语句,一层一层剥离,就很容易得到了整个执行计划的顺序,这里我把按照上述原则解析出来的执行计划的顺序paste出来,如下所示:
第一步:TABLE ACCESS FULL | OWBATN | 1 | 34 | 851 (5)| 00:00:11 |
第二步:TABLE ACCESS FULL | UPLTER | 316K| 6175K| 1118 (3)| 00:00:14 |
第三步:BUFFER SORT | | 316K| 6175K| 1118 (3)| 00:00:14 |
第四步:MERGE JOIN CARTESIAN | | 470K| 24M| 1969 (4)| 00:00:24 |
第五步:TABLE ACCESS FULL | OWBATN | 20956 | 695K| 852 (5)| 00:00:11 |
第六步:INDEX FAST FULL SCAN | IDX_UPLTER_