您好,登錄后才能下訂單哦!
繼續驗證使用索引時,cbc latch相關情況,使用solaris中的dtrace
編寫dtrace腳本
more cbc.d #!/usr/sbin/dtrace -s -n char *memnr; int latchaddr; dtrace:::BEGIN { i=1; latchaddr=0; } pid$1::sskgslcas:entry { memnr=copyin(arg0,12); latchaddr=arg0; printf("[%2x%2x%2x%2x|%2x%2x%2x%2x|%2x%2x%2x%2x]",memnr[3],memnr[2],memnr[1],memnr[0],memnr[7],memnr[6],memnr[5],memnr[4],memnr [11],memnr[10],memnr[9],memnr[8]); printf("i=%d PID::entry:==%s:%s:%s:%s %x %x %x %x %x %x",i, probeprov, probemod, probefunc, probename,arg0,arg1,arg2,arg3,arg4,arg5); i=i+1; } pid$1::sskgslcas:return { memnr=copyin(latchaddr,12); printf("[%2x%2x%2x%2x|%2x%2x%2x%2x|%2x%2x%2x%2x]",memnr[3],memnr[2],memnr[1],memnr[0],memnr[7],memnr[6],memnr[5],memnr[4],memnr [11],memnr[10],memnr[9],memnr[8]); printf("i=%d PID::entry:==%s:%s:%s:%s %x %x %x",i, probeprov, probemod, probefunc, probename,latchaddr,arg0,arg1); i=i+1; }
先測試非唯一索引:
session1:創建相應對象,并多次執行查詢語句
create table a as select * from dba_objects; create index idx_a on a(object_id); select owner from a where object_id='30000'; SQL> select c.sid,spid,pid,a.SERIAL# from (select sid from v$mystat where rownum<=1) c,v$session a,v$process b where c.sid=a.sid and a.paddr=b.addr; SID SPID PID SERIAL# ---------- ------------ ---------- ---------- 159 1355 15 9
session2:查詢出block
set pagesize 50000 set linesize 10000 select file#,dbablk,tch,ba,HLADDR from x$bh a,dba_objects b where a.obj=b.data_object_id and object_name='IDX_A' order by FILE#,DBABLK; FILE# DBABLK TCH BA HLADDR ---------- ---------- ---------- -------- -------- 1 60641 0 5A4A8000 5F13949C 1 60642 0 5A350000 5F0FC938 1 60642 4 595EA000 5F0FC938 1 62091 0 58116000 5F14F564 1 62091 4 58468000 5F14F564 SQL> select segment_name,header_file,header_block from dba_segments where segment_name=upper('IDX_A'); SEGMENT_NAME HEADER_FILE HEADER_BLOCK --------------------------------------------------------------------------------- ----------- ------------ IDX_A 1 60641
60641對段頭塊,60642為索引的root塊,62091為leaf塊
執行dtrace腳本,做跟蹤,然后回到session1中再次執行查詢語句
./cbc.d 1355 > logic_read.log
bash-3.2# cat logic_read.log|wc -l
25
session1:60642對應5F0FC938,在索引掃描時,對root塊是共享cbc latch
SQL> oradebug call sskgslcas 0x5f0fc938 0 1 Function returned 1 SQL> select owner from a where object_id='30000'; OWNER ------------------------------ PUBLIC PUBLIC SQL> oradebug call sskgsldecr 0x5f0fc938 1 Function returned 1
62091為leaf塊,在索引掃描時,對leaf塊是一次共享cbc latch,三次獨占cbc latch
bash-3.2# cat logic_read.log|grep -i 5F14F564 1 53243 sskgslcas:entry [ 0 0 0 0| 0 0 6 8| 0 0 07a]i=5 PID::entry:==pid1355:oracle:sskgslcas:entry 5f14f564 0 1 fdc4d278 fdc4d270 fdc4d134 1 53244 sskgslcas:return [ 0 0 0 1| 0 0 6 8| 0 0 07a]i=6 PID::entry:==pid1355:oracle:sskgslcas:return 5f14f564 16 1 1 53243 sskgslcas:entry [ 0 0 0 0| 0 0 6 9| 0 0 07a]i=11 PID::entry:==pid1355:oracle:sskgslcas:entry 5f14f564 0 2000000f ffffffff fdc4d278 fdc4d130 1 53244 sskgslcas:return [20 0 0 f| 0 0 6 9| 0 0 07a]i=12 PID::entry:==pid1355:oracle:sskgslcas:return 5f14f564 16 1 1 53243 sskgslcas:entry [ 0 0 0 0| 0 0 6 a| 0 0 07a]i=13 PID::entry:==pid1355:oracle:sskgslcas:entry 5f14f564 0 2000000f c4a89cc fdc4d134 fdc4d270 1 53244 sskgslcas:return [20 0 0 f| 0 0 6 a| 0 0 07a]i=14 PID::entry:==pid1355:oracle:sskgslcas:return 5f14f564 16 1 1 53243 sskgslcas:entry [ 0 0 0 0| 0 0 6 b| 0 0 07a]i=15 PID::entry:==pid1355:oracle:sskgslcas:entry 5f14f564 0 2000000f 0 fdc4d278 fdc4d26c 1 53244 sskgslcas:return [20 0 0 f| 0 0 6 b| 0 0 07a]i=16 PID::entry:==pid1355:oracle:sskgslcas:return 5f14f564 16 1
上面是索引為非唯一索引時,cbc latch相關情況下面過程為測試
再測試唯一索引:
create table a as select * from dba_objects; create unique index idx_a on a(object_id); SQL> select c.sid,spid,pid,a.SERIAL# from (select sid from v$mystat where rownum<=1) c,v$session a,v$process b where c.sid=a.sid and a.paddr=b.addr; SID SPID PID SERIAL# ---------- ------------ ---------- ---------- 147 1374 16 12 select owner from a where object_id='30000'; SQL> select file#,dbablk,tch,ba,HLADDR from x$bh a,dba_objects b where a.obj=b.data_object_id and object_name='IDX_A' order by FILE#,DBABLK; FILE# DBABLK TCH BA HLADDR ---------- ---------- ---------- -------- -------- 1 60641 1 595EA000 5F13949C 1 60642 4 5A752000 5F0FC938 1 61343 3 584A0000 5F122270 SQL> / FILE# DBABLK TCH BA HLADDR ---------- ---------- ---------- -------- -------- 1 60641 1 595EA000 5F13949C 1 60642 6 5A752000 5F0FC938 1 61343 5 584A0000 5F122270 SQL> select segment_name,header_file,header_block from dba_segments where segment_name=upper('IDX_A'); SEGMENT_NAME -------------------------------------------------------------------------------- HEADER_FILE HEADER_BLOCK ----------- ------------ IDX_A 1 60641 60642為root塊,61343為leaf塊 bash-3.2# cat logic_read1.log CPU ID FUNCTION:NAME 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 074| 0 0 0 0]i=1 PID::entry:==pid1374:oracle:sskgslcas:entry 5ceb6fe8 0 930001 5d76abac 5ceb6fe8 5f8c4c6c 0 53244 sskgslcas:return [ 093 0 1| 0 0 074| 0 0 0 0]i=2 PID::entry:==pid1374:oracle:sskgslcas:return 5ceb6fe8 16 1 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 5db| 0 0 07a]i=3 PID::entry:==pid1374:oracle:sskgslcas:entry 5f0fc938 0 1 804510c 8045104 fdc18bf8 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 5db| 0 0 07a]i=4 PID::entry:==pid1374:oracle:sskgslcas:return 5f0fc938 16 1 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 5 2| 0 0 07a]i=5 PID::entry:==pid1374:oracle:sskgslcas:entry 5f122270 0 1 804510c 8045104 fdc18bf8 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 5 2| 0 0 07a]i=6 PID::entry:==pid1374:oracle:sskgslcas:return 5f122270 16 1 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 698| 0 0 07a]i=7 PID::entry:==pid1374:oracle:sskgslcas:entry 5f106340 0 1 fdc18f60 fdc18f58 fdc18f00 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 698| 0 0 07a]i=8 PID::entry:==pid1374:oracle:sskgslcas:return 5f106340 16 1 0 53243 sskgslcas:entry [ 0 0 0 1| 0 0 075| 0 0 0 0]i=9 PID::entry:==pid1374:oracle:sskgslcas:entry 5ceb6fe8 1 930000 c4a88d0 5ceb6fe8 5f8c4c6c 0 53244 sskgslcas:return [ 093 0 0| 0 0 075| 0 0 0 0]i=10 PID::entry:==pid1374:oracle:sskgslcas:return 5ceb6fe8 16 1 bash-3.2# cat logic_read1.log|grep -i 5F0FC938 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 5db| 0 0 07a]i=3 PID::entry:==pid1374:oracle:sskgslcas:entry 5f0fc938 0 1 804510c 8045104 fdc18bf8 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 5db| 0 0 07a]i=4 PID::entry:==pid1374:oracle:sskgslcas:return 5f0fc938 16 1 bash-3.2# cat logic_read1.log|grep -i 5F122270 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 5 2| 0 0 07a]i=5 PID::entry:==pid1374:oracle:sskgslcas:entry 5f122270 0 1 804510c 8045104 fdc18bf8 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 5 2| 0 0 07a]i=6 PID::entry:==pid1374:oracle:sskgslcas:return 5f122270 16 1 bash-3.2# cat logic_read1.log|grep -i 5F106340 0 53243 sskgslcas:entry [ 0 0 0 0| 0 0 698| 0 0 07a]i=7 PID::entry:==pid1374:oracle:sskgslcas:entry 5f106340 0 1 fdc18f60 fdc18f58 fdc18f00 0 53244 sskgslcas:return [ 0 0 0 1| 0 0 698| 0 0 07a]i=8 PID::entry:==pid1374:oracle:sskgslcas:return 5f106340 16 1 唯一索引掃描時,對root塊與leaf塊都是一次共享cbc latch,對表塊也是一次共享cbc latch
邏輯讀時的cbc latch(一):http://qhd2004.blog.51cto.com/629417/1576554
邏輯讀時的cbc latch(二):http://qhd2004.blog.51cto.com/629417/1576579
參考:http://blog.itpub.net/321157/viewspace-730936/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。