一条SQL语句执行后,如何找到其在shared pool里占用的chunks,做了一个简单的测试:
---先清空shared pool
alter system flush shared_pool;
---执行sql语句
select * from scott.t1 where username='SYS';
USERNAME USER_ID CREATED
------------------------------ ---------- -----------------
SYS 0 20141110 21:16:12
---这时我们可以看到一个父游标和一个子游标生成了
set linesize 180 pagesize 100 word wrapped
col kglnaobj format a100 word_wrapped
select kglhdadr,kglhdpar,kglnaobj from x$kglob where kglnaobj like 'select * from scott.t1 where username=%';
KGLHDADR KGLHDPAR KGLNAOBJ
---------------- ---------------- ----------------------------------------------------------------------------------------------------
07000001B84F85E8 07000001B8670420 select * from scott.t1 where username='SYS' <---KGLHDADR!=KGLHDPAR,07000001B84F85E8是存放子游标handle的地址
07000001B8670420 07000001B8670420 select * from scott.t1 where username='SYS' <---KGLHDADR=KGLHDPAR,07000001B8670420是存放父游标handle的地址
---以上查出的结果中都是父/子游标handle所在的地址,因为handle会最终指向父/子游标,handle所在的地址也可以看成是指向handle的指针,我们通过shared pool的dump可以找到07000001B8670420这个指向handle的指针,其位于起始地址为7000001b86703f0所在的chunk内,该chunk正是父游标的handle
alter session set tracefile_identifier='level2dmp.txt';
alter system set events 'immediate trace name heapdump level 2';
***tstdb1_ora_3670294_level2dmp.txt trace文件里的信息,我们能看到07000001B8670420这一地址位于"sga heap(1,1)"的EXTENT 1段落中,每个extent的大小称为一个granule size,这里的granule size为16777216 bytes
HEAP DUMP heap desc=700000000056950
extent sz=0xfe0 alt=248 het=32767 rec=9 flg=-126 opc=0
parent=0 owner=0 nex=0 xsz=0x1000000 heap=0
fl2=0x20, nex=0, dsxvers=1, dsxflg=0x0
dsx first ext=0xb8000000
latch set 1 of 4
durations enabled for this heap
reserved granules for root 11 (granule size 16777216)
EXTENT 0 addr=70000019b000000
。。。。省略部分内容
EXTENT 1 addr=7000001b8000000
Chunk 7000001b8000058 sz= 80 perm "perm " alo=80
Chunk 7000001b80000a8 sz= 48 R-freeable "reserved stoppe"
Chunk 7000001b80000d8 sz= 839416 R-free " "
。。。。省略部分内容
Chunk 7000001b866fb90 sz= 1072 recreate "KQR PO " latch=7000001b0d5edb0
Chunk 7000001b866ffc0 sz= 1072 recreate "KQR PO " latch=7000001b0d5edb0
Chunk 7000001b86703f0 sz= 584 recreate "KGLHD " latch=0 <---父游标handle的地址(也即指向父游标handle的指针)包含在起始地址为7000001b86703f0的chunk里,这个chunk的大小为584bytes,类型为KGLHD
Chunk 7000001b8670638 sz= 160 free " "
Chunk 7000001b86706d8 sz= 528 recreate "KGLHD " latch=0
。。。。省略部分内容
---通过父游标的handle所在地址能够关联出父游标heap 0的描述符地址
col KGLNAOBJ format a80
set linesize 190 pagesize 20
select kglhdadr,kglnaobj,kglobhd0 from x$kglob where kglhdadr='07000001B8670420';
KGLHDADR KGLNAOBJ KGLOBHD0
---------------- -------------------------------------------------------------------------------- ----------------
07000001B8670420 select * from scott.t1 where username='SYS' 070000019BB137F0 <---父游标heap 0的描述符(Descriptor)所在地址