DB2表的LOB字段为什么没有使用指定的表空间

问题描述:

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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值