[20231026]bbed檢視索引kd_off結構的問題.txt

lfree發表於2023-10-30

[20231026]bbed檢視索引kd_off結構的問題.txt

--//使用bbed檢視索引kd_off結構時存在問題,前面兩項指向的偏移不對,從kd_off[2]算起,而且記錄的是相對偏移=絕對偏移-kdxle偏移.
--//遺漏的兩項可以透過最大的kd_off項記錄的地址+2 ,+4 獲得.
--//dump offset kd_off[max]+2 count 2
--//dump offset kd_off[max]+4 count 2

--//每次看最後兩項比較麻煩,先給dump offset kd_off[max]+2 count 2,然後大小頭顛倒, 計算出數字,在此基礎上加上kdxle偏移,
--//獲得正確的偏移NNNN,然後再使用如下命令查詢。
x /rxxx offset  NNNN

--//自己嘗試編寫指令碼實現正確的輸出,並附帶輸出正確的x執行命令格式。主要自己很久不寫bash shell指令碼,拿來練習。
$ cat kd_off.sh
#! /bin/bash
# display bbed of kd_off structure and x command.
# argument1=dba  argument2=bbed x format

ff="/r"${2}
a=$1

# get kd_off[max-2] and kdxle of address.
kd_off_max=$(echo p dba $a kd_off | rlbbed | grep kd_off | sed -n '$p' |awk '{print substr($3,2)}')
kdxle_offset=$(echo map dba $a | rlbbed | grep kdxle | awk '{print substr($5,2)}')
kd_off_size=$(echo map dba $a| rlbbed | grep 'b2 kd_off' | sed -e 's/^.*\[//;s/].*$//' )
#echo kd_off_max=$kd_off_max kdxle_offset=$kdxle_offset  kd_off_size=$kd_off_size

# get kd_off[max-1] and kd_off[max] of offset
kd_off_offset=$(echo dump dba $a offset $((kd_off_max+2)) count 4 | rlbbed  | grep -A1 --  '----' | sed -n '$p' | tr -d ' \r')
kd_off_offset=$(echo $kd_off_offset)
kd_off_offset1=$(echo $kd_off_offset|awk '{print substr($a,3,2) substr($1,1,2)}')
kd_off_offset2=$(echo $kd_off_offset|awk '{print substr($a,7,2) substr($1,5,2)}')

#echo kd_off_offset=$kd_off_offset kd_off_offset1=$kd_off_offset1 kd_off_offset2=$kd_off_offset2

# display x command
# echo p dba $a kd_off | rlbbed | grep kd_off | sed -n '3,$p' | awk '{print  $2}'| xargs -IQ echo x $ff dba $a '*'Q
seq 2 $((kd_off_size-1)) | xargs -IQ echo x $ff dba $a '*'kd_off[Q]
echo x $ff dba $a offset  $((0x${kd_off_offset1}+kdxle_offset))
echo x $ff dba $a offset  $((0x${kd_off_offset2}+kdxle_offset))
echo " "

# display kd_off structure
echo p dba $a kd_off | rlbbed | grep kd_off | sed -n '3,$p' | awk  -F'[][]' '{printf "%s[%d]%40s\n",$1,$2-2,$3}'
printf "%s %s %34s %9s\n" b2 kd_off[$((kd_off_size-2))]  @$((kd_off_max+2))  $((0x$kd_off_offset1))
printf "%s %s %34s %9s\n" b2 kd_off[$((kd_off_size-1))]  @$((kd_off_max+4))  $((0x$kd_off_offset2))

--//驗證測試看看:
1.環境:
SCOTT@test01p> @ver1
PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.2.0.1.0     Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0

2.測試:
SCOTT@test01p> @ seg2 pk_emp
SCOTT@test01p> @ pr
==============================
SEG_MB                        : 0
SEG_OWNER                     : SCOTT
SEG_SEGMENT_NAME              : PK_EMP
SEG_PARTITION_NAME            :
SEG_SEGMENT_TYPE              : INDEX
SEG_TABLESPACE_NAME           : USERS
BLOCKS                        : 8
HDRFIL                        : 11
HDRBLK                        : 154
PL/SQL procedure successfully completed.
--//索引的root,葉子在dba=11,155. 使用bbed for windows無法識別資料檔案os頭,塊偏移+1,輸入11,156.

BBED> p dba 11,156 kd_off
b2 kd_off[0]                                @132      8036  --//8036+100(kdxle的偏移)=8136 表示索引資料的結尾,中間還
                                                            --//保留8188-8136 = 52,不知道什麼用處。
b2 kd_off[1]                                @134      0     --//kd_off[0],kd_off[1]執行的偏移不對,我估計oracle改變了
                                                            --//kdxle結構,這4個位元組的內容應該屬於kdxle。而bbed版本沒
                                                            --//有維護跟上這種調整。
b2 kd_off[2]                                @136      8024
b2 kd_off[3]                                @138      8012
b2 kd_off[4]                                @140      8000
b2 kd_off[5]                                @142      7988
b2 kd_off[6]                                @144      7976
b2 kd_off[7]                                @146      7964
b2 kd_off[8]                                @148      7952
b2 kd_off[9]                                @150      7940
b2 kd_off[10]                               @152      7928
b2 kd_off[11]                               @154      7916
b2 kd_off[12]                               @156      7904
b2 kd_off[13]                               @158      7893

$ ./kd_off.sh  11,156 n
x /rn dba 11,156 *kd_off[2]
x /rn dba 11,156 *kd_off[3]
x /rn dba 11,156 *kd_off[4]
x /rn dba 11,156 *kd_off[5]
x /rn dba 11,156 *kd_off[6]
x /rn dba 11,156 *kd_off[7]
x /rn dba 11,156 *kd_off[8]
x /rn dba 11,156 *kd_off[9]
x /rn dba 11,156 *kd_off[10]
x /rn dba 11,156 *kd_off[11]
x /rn dba 11,156 *kd_off[12]
x /rn dba 11,156 *kd_off[13]
x /rn dba 11,156 offset 7981
x /rn dba 11,156 offset 7969

b2 kd_off[0]                                @136      8024
b2 kd_off[1]                                @138      8012
b2 kd_off[2]                                @140      8000
b2 kd_off[3]                                @142      7988
b2 kd_off[4]                                @144      7976
b2 kd_off[5]                                @146      7964
b2 kd_off[6]                                @148      7952
b2 kd_off[7]                                @150      7940
b2 kd_off[8]                               @152      7928
b2 kd_off[9]                               @154      7916
b2 kd_off[10]                               @156      7904
b2 kd_off[11]                               @158      7893
b2 kd_off[12]                               @160      7881
b2 kd_off[13]                               @162      7869

--//注:前面顯示的命令是x命令,後面的顯示是正確的kd_off結構,意義不大!!

BBED> x /rn dba 11,156 offset 7981
rowdata[16]                                 @7981
-----------
flag@7981:     0x00 (NONE)
lock@7982:     0x02
keydata[6]:    0x02  0xc0  0x00  0x94  0x00  0x0c
data key:
col    0[3] @7990: 7902

BBED> x /rn dba 11,156 offset 7969
rowdata[4]                                  @7969
----------
flag@7969:     0x00 (NONE)
lock@7970:     0x02
keydata[6]:    0x02  0xc0  0x00  0x94  0x00  0x0d
data key:
col    0[3] @7978: 7934

SCOTT@test01p> select * from (select * from emp order by empno desc) where rownum<=2 ;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7934 MILLER     CLERK           7782 1982-01-23 00:00:00       1300                    10
      7902 FORD       ANALYST         7566 1981-12-03 00:00:00       3000                    20
--//完全能對上.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2991956/,如需轉載,請註明出處,否則將追究法律責任。

相關文章