- 最后登录
- 2023-8-16
- 在线时间
- 1686 小时
- 威望
- 2135
- 金钱
- 50532
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 5207
- 精华
- 39
- 积分
- 2135
- UID
- 2
|
12#
发表于 2013-10-15 10:29:27
create table zwh_main (id number, c1 varchar2(50));
create table zwh_sub (id number, id2 number);
insert into zwh_main select rownum, 'hello' from dual connect by level <10000;
insert into zwh_sub select rownum,rownum from dual connect by level <1000;
create index idx_zwh_main on zwh_main(id);
create index idx_zwh_sub on zwh_sub(id);
set linesize 150
set long 999
set pagesize 99
exec dbms_stats.gather_table_stats(user,'ZWH_MAIN');
exec dbms_stats.gather_table_stats(user,'ZWH_SUB');
alter system flush buffer_cache;
set linesize 200 pagesize 2000
alter session set statistics_level=ALL;
alter session set events '10046 trace name context forever,level 8';
select zwh_main.*,(select sum(id2) from zwh_sub where zwh_sub.id=zwh_main.id) s
from zwh_main
where zwh_main.id=100;
select * from table(dbms_xplan.display_cursor(null,null,'TYPICAL IOSTATS LAST'));
oradebug setmypid
oradebug tracefile_name
------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 2 (100)| | 1 |00:00:00.01 | 4 | 3 |
| 1 | SORT AGGREGATE | | 1 | 1 | 8 | | | 1 |00:00:00.01 | 3 | 3 |
| 2 | TABLE ACCESS BY INDEX ROWID| ZWH_SUB | 1 | 1 | 8 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 3 | 3 |
|* 3 | INDEX RANGE SCAN | IDX_ZWH_SUB | 1 | 1 | | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 2 | 2 |
| 4 | TABLE ACCESS BY INDEX ROWID | ZWH_MAIN | 1 | 1 | 10 | 2 (0)| 00:00:01 | 1 |00:00:00.01 | 4 | 3 |
|* 5 | INDEX RANGE SCAN | IDX_ZWH_MAIN | 1 | 1 | | 1 (0)| 00:00:01 | 1 |00:00:00.01 | 3 | 2 |
------------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("ZWH_SUB"."ID"=:B1)
5 - access("ZWH_MAIN"."ID"=100)
SQL> select object_id,object_name from dba_objects where object_id in (92620,92618,92621,92619);
OBJECT_ID OBJECT_NAME
---------- --------------------
92618 ZWH_MAIN
92619 ZWH_SUB
92620 IDX_ZWH_MAIN
92621 IDX_ZWH_SUB
WAIT #140552674633184: nam='Disk file operations I/O' ela= 96 FileOperation=2 fileno=1 filetype=2 obj#=92620 tim=1381803018648141
WAIT #140552674633184: nam='db file sequential read' ela= 45 file#=1 block#=109393 blocks=1 obj#=92620 tim=1381803018648264
WAIT #140552674633184: nam='db file sequential read' ela= 18 file#=1 block#=109394 blocks=1 obj#=92620 tim=1381803018648444
WAIT #140552674633184: nam='db file sequential read' ela= 29 file#=1 block#=109361 blocks=1 obj#=92618 tim=1381803018648573
WAIT #140552674633184: nam='db file sequential read' ela= 19 file#=1 block#=109417 blocks=1 obj#=92621 tim=1381803018648804
WAIT #140552674633184: nam='db file sequential read' ela= 17 file#=1 block#=109418 blocks=1 obj#=92621 tim=1381803018648903
WAIT #140552674633184: nam='db file sequential read' ela= 18 file#=1 block#=109369 blocks=1 obj#=92619 tim=1381803018648986
FETCH #140552674633184:c=0,e=1216,p=6,cr=6,cu=0,mis=0,r=1,dep=0,og=1,plh=4037143566,tim=1381803018649065
WAIT #140552674633184: nam='SQL*Net message from client' ela= 379 driver id=1650815232 #bytes=1 p3=0 obj#=92619 tim=1381803018649537
FETCH #140552674633184:c=0,e=17,p=0,cr=1,cu=0,mis=0,r=0,dep=0,og=1,plh=4037143566,tim=1381803018649616
STAT #140552674633184 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=3 pr=3 pw=0 time=364 us)'
STAT #140552674633184 id=2 cnt=1 pid=1 pos=1 obj=92619 op='TABLE ACCESS BY INDEX ROWID ZWH_SUB (cr=3 pr=3 pw=0 time=273 us cost=2 size=8 card=1)'
STAT #140552674633184 id=3 cnt=1 pid=2 pos=1 obj=92621 op='INDEX RANGE SCAN IDX_ZWH_SUB (cr=2 pr=2 pw=0 time=190 us cost=1 size=0 card=1)'
STAT #140552674633184 id=4 cnt=1 pid=0 pos=2 obj=92618 op='TABLE ACCESS BY INDEX ROWID ZWH_MAIN (cr=4 pr=3 pw=0 time=818 us cost=2 size=10 card=1)'
STAT #140552674633184 id=5 cnt=1 pid=4 pos=1 obj=92620 op='INDEX RANGE SCAN IDX_ZWH_MAIN (cr=3 pr=2 pw=0 time=674 us cost=1 size=0 card=1)'
WAIT #140552674633184: nam='SQL*Net message to client' ela= 4 driver id=1650815232 #bytes=1 p3=0 obj#=92619 tim=1381803018649949
查看EM 中的执行计划顺序, 同样是错误的
|
|