[20140729]关于LOB字段存储特性3.txt
--前面我们看到只要lob信息在块外,扫描执行读到这些信息都存在物理读。
SCOTT@test> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
create table t (id number,idx number,col1 clob,col2 clob, col3 clob) lob (col3) store as (disable storage in row);
create unique index i_t_id on t(id);
insert into t values (1,1,lpad('b',100,'b'),lpad('a',4000,'a'),lpad('a',4000,'a'));
commit ;
execute dbms_stats.gather_table_stats(user,'t',cascade=>true,method_opt=>'for all columns size 1',no_invalidate=>false);
--安装的语言选择NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK.这样即使1个英文字符也占用2个字节.
--这样都是插入8000字节,lob的信息保存在块外(我的数据库是8k的).
--题外话题:最好使用blob类型,这样可以原样保存,特别保存的文本是英文的情况下,空间浪费比较严重,对于中文字符集.
--col1=lpad('b',100,'b'),应该在块内。
--col2=lpad('a',4000,'a'),长度超出3964,应该在块外。
--col3=lpad('b',4000,'b'),使用ENABLE STORAGE IN ROW,无论如何都在块外。
SCOTT@test> select id,col2 from t where id=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
2 physical reads
0 redo size
--如果col2是ENABLE STORAGE IN ROW,由于长度大于3964,保存在块外,导致 consistent gets增加到4,同时存在
--2个physical reads,无论执行多少次.
SCOTT@test> select id,col3 from t where id=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
2 physical reads
0 redo size
--对比发现,ENABLE/DISABLE STORAGE IN ROW两者的逻辑读差异很大,前者仅仅4个逻辑读,而后者仅仅11个逻辑读,而且每次都是2个物理读。
SCOTT@test> alter table t modify lob (col2) (CACHE);
Table altered.
SCOTT@test> alter table t modify lob (col3) (CACHE);
Table altered.
SCOTT@test> select id,col2 from t where id=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
SCOTT@test> select id,col3 from t where id=1;
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
--可以发现修改lob属性为cache后,物理读消失。
--如果应用要反复读取lob字段,设置lob的cache属性能提高读取性能,特别对于asm以及使用裸设备的情况。
--但是必须权衡,如果lob占用data buffer 太多,也可能会影响其他块在data buffer。