问题描述:
DB2中的LOB字段并未占用指定的表空间。 创建表T2,指定LOB字段使用表空间LONGTBS,但插入一些数据之后,发现LONGTBS表空间使用并未增长。
$ db2 "create tablespace tbs2 managed by automatic storage"
$ db2 "create tablespace longtbs managed by automatic storage"
$ db2 "create table t2(id int, address clob (32 k)) in tbs2 long in LONGTBS"
$ db2 "list tablespaces show detail"
..
Tablespace ID = 9
Name = TBS2
Used pages = 160
Tablespace ID = 10
Name = LONGTBS
Used pages = 224
$ db2 "runstats on table e97q9a.t2"
$ db2 "select npages from syscat.tables where tabname='T2'"
NPAGES
--------------------
0
db2 "SELECT substr(TABSCHEMA,1,10) as TABSCHEMA, substr(TABNAME,1,10) as TABNAME, DATA_OBJECT_L_SIZE, LOB_OBJECT_L_SIZE FROM SYSIBMADM.ADMINTABINFO WHERE TABNAME='T2' "
TABSCHEMA TABNAME DATA_OBJECT_L_SIZE LOB_OBJECT_L_SIZE
---------- ---------- -------------------- --------------------
E97Q9A T2 512 520
1 record(s) selected.
//insert some data
db2 "runstats on table e97q9a.t2"
db2 "select npages from syscat.tables where tabname='T2'"
NPAGES
--------------------
1102
1 record(s) selected.
db2 "SELECT substr(TABSCHEMA,1,10) as TABSCHEMA, substr(TABNAME,1,10) as TABNAME, DATA_OBJECT_L_SIZE, LOB_OBJECT_L_SIZE FROM SYSIBMADM.ADMINTABINFO WHERE TABNAME='T2' "
TABSCHEMA TABNAME DATA_OBJECT_L_SIZE LOB_OBJECT_L_SIZE
---------- ---------- -------------------- --------------------
E97Q9A T2 9216 520 <--无变化
1 record(s) selected.
db2 "list tablespaces show detail"
Tablespace ID = 9
Name = TBS2
Used pages = 1248
Tablespace ID = 10
Name = LONGTBS
Used pages = 224 <--无变化
可以看到插入数据之后,Create table指定的LOB表空间使用页并没有增加,ADMINTABINFO显示LOB_OBJECT_L_SIZE也没有增加。这是什么原因呢?
产生原因:
产生的原因是,如果插入的LOB字段不够长,DB2会把它存储为inline LOBs, 行为和普通字段并无差别。This feature is also implicitly enabled for all LOB columns in new or existing tables (when LOB columns are added), and for all existing LOB columns on database upgrade. Every LOB column has reserved row space that is based on its defined maximum size. An implicit INLINE LENGTH value for each LOB column is defined automatically and stored as if it had been explicitly specified.
在后来的测试中,大大增加了真正插入数据的长度,就会使用LONGTBS表空间了。
参考资料:
IBM Knowledge Center - Inline LOBs improve performance