关于physical guess

| No Comments

在"logical rowid的结构"这篇文章里,我人为构造了一个stalephysical guess的例子,这里我们继续,做如下的三个测试:

1修改logical rowidprimary key但不修改physical guess,以验证oraclephysical guess准确的情况下是否需要primary key

2、同时修改logical rowidprimary keyphysical guess,以验证oracle在这样的情况下的表现。

3修改IOT里一条记录的primary key,验证在这种情况下其索引上的physical guess是否会stale

 

这里的测试对象是ID2的那条记录:

SQL> select id,rowid,dump(rowid,16) from t3;

 

        ID ROWID                           DUMP(ROWID,16)

---------- ------------------------------- --------------------------------------------------------------------------------

         1 *BCFAABMCwQL+                 Typ=208 Len=10: 2,4,21,40,0,13,2,c1,2,fe

         2 *BCFAABMCwQP+                 Typ=208 Len=10: 2,4,21,40,0,13,2,c1,3,fe

         3 *BCFAABMCwQT+                 Typ=208 Len=10: 2,4,21,40,0,13,2,c1,4,fe

         4 *BCFAABQCwQX+                 Typ=208 Len=10: 2,4,21,40,0,14,2,c1,5,fe

 

这是未修改前的查询结果:

SQL>  select id,substr(c2,1,1) from t3 where c1='B';

 

        ID SUBSTR(C2,1,1)

---------- --------------

         2 B

 

具体的测试过程我就不再赘述了,我们来看一下上述三个测试的结果。

 

测试一:

这里我是把主键ID=2改为3,即C1 04,但不改physical guess 0x21400013

BBED> modify /x 0x0400014202c1042c00010421400013

Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y

 File: /dras20/astca/test01.dbf (133)

 Block: 42               Offsets: 8094 to 8191           Dba:0x2140002a

------------------------------------------------------------------------

 04000142 02c1042c 00010421 40001304 00014102 c1022c00 01042140 0013c30d

 1c1eac00 03000100 010040dd 67000100 40dd6700 0102c122 02c15b04 c30d1c0e

 ac000300 01000100 40dd6700 000040dd 67000002 c12202c1 5b04c30d 1b62cdec

 0601

 

 <32 bytes per line>

 

改完后startup上述数据库再执行上述查询:

SQL> select id,substr(c2,1,1) from t3 where c1='B';

 

        ID SUBSTR(C2,1,1)

---------- --------------

         3 C

 

SQL> select /*+ full(t3) */id,substr(c2,1,1) from t3 where c1='B';

 

        ID SUBSTR(C2,1,1)

---------- --------------

         2 B

 

从测试结果里可以看到,只要我改了主键,即使physical guess是准确的,oracle这里也会得到错误的值。

 

既然测试一的结果是这样,那测试二也就不用做了。

 

测试三:

ID=1的那条记录的physical guess0x21400013,我现在把ID=1改成ID=5,这时候ID=1的那条记录必然要挪到0x21400014中,等修改完成后我们再dump一下,看看ID=5的那条记录所对应的index blockphysical guess0x21400013还是0x21400014

SQL> update t3 set id=5 where id=1;

 

1 row updated

 

SQL> commit;

 

Commit complete

 

SQL> select id,rowid,dump(rowid,16) from t3;

 

        ID ROWID                           DUMP(ROWID,16)

---------- ------------------------------- --------------------------------------------------------------------------------

         2 *BCFAABMCwQP+                 Typ=208 Len=10: 2,4,21,40,0,13,2,c1,3,fe

         3 *BCFAABMCwQT+                 Typ=208 Len=10: 2,4,21,40,0,13,2,c1,4,fe

         4 *BCFAABQCwQX+                 Typ=208 Len=10: 2,4,21,40,0,14,2,c1,5,fe

         5 *BCFAABQCwQb+                 Typ=208 Len=10: 2,4,21,40,0,14,2,c1,6,fe

 

SQL> alter system checkpoint;

 

System altered

 

Dump一下133_42这个index block

row#0[8017] flag: K--D-, lock: 2

col 0; len 1; (1):  41

col 1; len 2; (2):  c1 02

tl: 8 fb: --H-FL-- lb: 0x0  cc: 1

col  0: [ 4]

Dump of memory from 0x0000000110275FB8 to 0x0000000110275FBC

110275FB0                   21400013                   [!@..]   

row#1[7957] flag: K----, lock: 2

col 0; len 1; (1):  41

col 1; len 2; (2):  c1 06

tl: 8 fb: --H-FL-- lb: 0x0  cc: 1

col  0: [ 4]

Dump of memory from 0x0000000110275F7C to 0x0000000110275F80

110275F70                            21400014              [!@..]

row#2[8002] flag: K----, lock: 0

col 0; len 1; (1):  42

col 1; len 2; (2):  c1 04

tl: 8 fb: --H-FL-- lb: 0x0  cc: 1

col  0: [ 4]

Dump of memory from 0x0000000110275FA9 to 0x0000000110275FAD

110275FA0                   04214000 13050201          [.!@.....]

row#3[7987] flag: K----, lock: 0

col 0; len 1; (1):  43

col 1; len 2; (2):  c1 04

tl: 8 fb: --H-FL-- lb: 0x0  cc: 1

col  0: [ 4]

Dump of memory from 0x0000000110275F9A to 0x0000000110275F9E

110275F90                   01042140 00130400          [..!@....]

row#4[7972] flag: K----, lock: 0

col 0; len 1; (1):  44

col 1; len 2; (2):  c1 05

tl: 8 fb: --H-FL-- lb: 0x0  cc: 1

col  0: [ 4]

Dump of memory from 0x0000000110275F8B to 0x0000000110275F8F

110275F80                   00010421 40001404          [...!@...]

----- end of leaf block dump -----

End dump data blocks tsn: 84 file#: 133 minblk 42 maxblk 42

 

现在ID=5所在的offset7957+68+24=8049

好了,我们现在来看其physical guess

BBED> set offset 8049

        OFFSET          8049

 

BBED> dump

 File: /dras20/astca/test01.dbf (133)

 Block: 42               Offsets: 8049 to 8191           Dba:0x2140002a

------------------------------------------------------------------------

 04020141 02c1062c 00010421 40001404 00014402 c1052c00 01042140 00140400

 014302c1 042c0001 04214000 13040001 4202c104 2c000104 21400013 05020141

 02c1022c 00010421 400013c3 0d1c1eac 00030001 00010040 dd670001 0040dd67

 000102c1 2202c15b 04c30d1c 0eac0003 00010001 0040dd67 00000040 dd670000

 02c12202 c15b04c3 0d1b621e 620601

 

 <32 bytes per line>

可以从结果里看到,现在ID=5的那条记录所对应的index blockphysical guess0x21400014,也就是说单纯的修改primary key并不会导致physical guessstale

Leave a comment