[20160725]字段超过255列的问题.txt
--曾经写过1篇blog, 如果字段很多超过255列,oracle选择多个行片保存。
[20121025]1条记录会有多少row pieces.txt => http://blog.itpub.net/267265/viewspace-747213/
--我以前的测试非常特殊,导致大量的行迁移。以前测试忽略的问题,自己重复看看:
1.测试:
spool a.sql
select 'create table t1 (' from dual
union all
select 'col'||lpad(rownum-1,3,'0')||' number(1),' from dual connect by level<=1000
union all
select 'constraint t1_pk primary key (col000));' from dual ;
2.插入看看:
SCOTT@book> insert into t1 (col000,col255) values (1,1);
1 row created.
SCOTT@book> commit ;
Commit complete.
SCOTT@book> select rowid,col000 from t1;
ROWID COL000
------------------ ----------
AAAXTaAAEAAAAL+AAB 1
SCOTT@book> @ &r/rowid AAAXTaAAEAAAAL+AAB
OBJECT FILE BLOCK ROW DBA TEXT
---------- ---------- ---------- ---------- -------------------- ----------------------------------------
95450 4 766 1 4,766 alter system dump datafile 4 block 766 ;
--如果注意看可以发现我仅仅插入1条记录,row=1.而不是0,说明存在2个行片。
SCOTT@book> alter system checkpoint ;
System altered.
3.通过bbed观察:
BBED> set dba 4,766
DBA 0x010002fe (16777982 4,766)
BBED> p kdbr
sb2 kdbr[0] @142 7804
sb2 kdbr[1] @144 7792
--//可以发现存在2个行片。
BBED> p kdbt
struct kdbt[0], 4 bytes @138
sb2 kdbtoffs @138 0
sb2 kdbtnrow @140 2
--//可以发现仅仅1个表,存在2条记录,说明这里如果字段超过255,存在多个行片,row数量不一定代表记录数量!!
BBED> x /rn *kdbr[1]
rowdata[0] @7916
----------
flag@7916: 0x28 (KDRHFF, KDRHFH)
lock@7917: 0x01
cols@7918: 1
nrid@7919:0x010002fe.0
col 0[2] @7925: 1
SCOTT@book> @ &r/dfb16 0x010002fe
RFILE# BLOCK# TEXT
---------- ---------- ------------------------------------------------------------
4 766 alter system dump datafile 4 block 766 ;
--//在相同1个数据块。
BBED> x /rn *kdbr[0]
rowdata[12] @7928
-----------
flag@7928: 0x04 (KDRHFL)
lock@7929: 0x01
cols@7930: 255
col 0[0] @7931: *NULL*
.....
col 252[0] @8183: *NULL*
col 253[0] @8184: *NULL*
col 254[2] @8185: 1
4.但是我还忽略一个小问题:
--这样情况的行链接在同1个块中,分析不会出现记录行迁移的情况。
create table CHAINED_ROWS (
owner_name varchar2(30),
table_name varchar2(30),
cluster_name varchar2(30),
partition_name varchar2(30),
subpartition_name varchar2(30),
head_rowid rowid,
analyze_timestamp date
);
SCOTT@book> analyze table t1 list chained rows;
Table analyzed.
SCOTT@book> analyze table t1 compute statistics;
Table analyzed.
SCOTT@book> select table_name, num_rows, chain_cnt, avg_row_len from user_tables where table_name='T1';
TABLE_NAME NUM_ROWS CHAIN_CNT AVG_ROW_LEN
---------- ---------- ---------- -----------
T1 1 0 269
5.再做一个转储:
SCOTT@book> alter system dump datafile 4 block 766 ;
System altered.
Block header dump: 0x010002fe
Object id on Block? Y
seg/obj: 0x174da csc: 0x03.1573b113 itc: 3 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10002f8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.011.0000365b 0x00c0046b.08ad.17 --U- 2 fsc 0x0000.1573b114
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.00000000
bdba: 0x010002fe
data_block_dump,data header at 0x7fa1d4cb227c
===============
tsiz: 0x1f80
hsiz: 0x16
pbl: 0x7fa1d4cb227c
76543210
flag=--------
ntab=1
nrow=2
frre=-1
fsbo=0x16
fseo=0x1e70
avsp=0x1e5a
tosp=0x1e5a
0xe:pti[0] nrow=2 offs=0
0x12:pri[0] offs=0x1e7c
0x14:pri[1] offs=0x1e70
block_row_dump:
tab 0, row 0, @0x1e7c
tl: 260 fb: -----L-- lb: 0x1 cc: 255
col 0: *NULL*
col 1: *NULL*
..
col 252: *NULL*
col 253: *NULL*
col 254: [ 2] c1 02
tab 0, row 1, @0x1e70
tl: 12 fb: --H-F--- lb: 0x1 cc: 1
nrid: 0x010002fe.0
col 0: [ 2] c1 02
end_of_block_dump
End dump data blocks tsn: 4 file#: 4 minblk 766 maxblk 766
--还可以发现建立3个ITL槽,这个跟以前建立表后再插入数据的情况有1点不同,那样建立的是2个ITL槽。另外注意看
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.011.0000365b 0x00c0046b.08ad.17 --U- 2 fsc 0x0000.1573b114
--//Lck=2,也就是lock 2个行片,而不是2条记录,当然一般字段数量小于255,就不会出现这种情况。
6.重新测试看看:
SCOTT@book> drop table t1 purge ;
Table dropped.
SCOTT@book> @ a.sql
Table created.
--//session 1:
SCOTT@book(46,1399)> insert into t1 (col000,col255) values (1,1);
1 row created.
SCOTT@book(46,1399)> insert into t1 (col000,col255) values (2,2);
1 row created.
SCOTT@book(46,1399)> commit ;
Commit complete.
SCOTT@book(46,1399)> select rowid,col000 from t1;
ROWID COL000
------------------ ----------
AAAXTdAAEAAAAL+AAB 1
AAAXTdAAEAAAAL+AAD 2
SCOTT@book(46,1399)> alter system checkpoint ;
System altered.
SCOTT@book(46,1399)> @ &r/rowid AAAXTdAAEAAAAL+AAB
OBJECT FILE BLOCK ROW DBA TEXT
---------- ---------- ---------- ---------- -------------------- ----------------------------------------
95453 4 766 1 4,766 alter system dump datafile 4 block 766 ;
SCOTT@book(46,1399)> alter system dump datafile 4 block 766 ;
System altered.
Block header dump: 0x010002fe
Object id on Block? Y
seg/obj: 0x174dd csc: 0x03.1573b5bc itc: 4 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10002f8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.005.0000365c 0x00c0046c.08ad.0c --U- 4 fsc 0x0000.1573b5d3
0x02 0x0000.000.00000000 0x00000000.0000.00 ---- 0 fsc 0x0000.00000000
0x03 0x0000.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.00000000
0x04 0x0000.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.00000000
bdba: 0x010002fe
data_block_dump,data header at 0x7fa1d4cb2294
===============
tsiz: 0x1f68
hsiz: 0x1a
pbl: 0x7fa1d4cb2294
76543210
flag=--------
ntab=1
nrow=4
frre=-1
fsbo=0x1a
fseo=0x1d48
avsp=0x1d2e
tosp=0x1d2e
0xe:pti[0] nrow=4 offs=0
0x12:pri[0] offs=0x1e64
0x14:pri[1] offs=0x1e58
0x16:pri[2] offs=0x1d54
0x18:pri[3] offs=0x1d48
--注意看ITL的数量现在是4,而不是前面测试的3。
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.005.0000365c 0x00c0046c.08ad.0c --U- 4 fsc 0x0000.1573b5d3
--//Lck=4.
--删除记录再插入多一些记录呢?
SCOTT@book(46,1399)> delete from t1;
2 rows deleted.
SCOTT@book(46,1399)> commit ;
Commit complete.
insert into t1 (col000,col255) values (1,1);
insert into t1 (col000,col255) values (2,2);
insert into t1 (col000,col255) values (3,3);
insert into t1 (col000,col255) values (4,4);
alter system checkpoint ;
alter system dump datafile 4 block 766 ;
Block header dump: 0x010002fe
Object id on Block? Y
seg/obj: 0x174dd csc: 0x03.1573b764 itc: 4 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10002f8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.005.0000365c 0x00c0046c.08ad.0c C--- 0 scn 0x0003.1573b5d3
0x02 0x000a.00f.0000ce39 0x00c0030f.2975.08 --U- 4 fsc 0x0218.1573b766
0x03 0x000a.01c.0000ce0c 0x00c0030f.2975.14 ---- 8 fsc 0x0000.00000000
0x04 0x0000.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.00000000
--依旧是4个ITL槽。
Block header dump: 0x010002fe
Object id on Block? Y
seg/obj: 0x174dd csc: 0x03.1573b764 itc: 4 flg: E typ: 1 - DATA
brn: 0 bdba: 0x10002f8 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0009.005.0000365c 0x00c0046c.08ad.0c C--- 0 scn 0x0003.1573b5d3
0x02 0x000a.00f.0000ce39 0x00c0030f.2975.08 --U- 4 fsc 0x0218.1573b766
0x03 0x000a.01c.0000ce0c 0x00c0030f.2975.14 ---- 8 fsc 0x0000.00000000
0x04 0x0000.000.00000000 0x00000000.0000.00 C--- 0 scn 0x0000.00000000
--不知道为什么这种情况会增加1个ITL槽。