[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
--//完全能对上.