[20140729]關於LOB欄位儲存特性3.txt

lfree發表於2014-08-02

[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。

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

相關文章