Lob欄位資料刪除,對應空間變化測試
阿新 • • 發佈:2019-01-27
由於遇到某個系統需要新新增LOB欄位,並且會有大量的插入刪除操作,所以需要確認下lob欄位在
大量資料操作之後總的體積大小變化是怎樣的。猜想lob欄位的大小並不會自動收縮,是持續增長的,需要手動干預收縮空間
--測試1 測試disable storage in row下的lob欄位
--create table建立測試表
create table T_LOB_TEST
(
id number(10) not null,
xml_content BLOB,
comm VARCHAR2(5)
)
lob(xml_content) store as
(disable storage in row
nocache logging)
;
--插入資料
declare
i number(10);
begin
for i in 1..1000
loop
insert into T_LOB_TEST values(i,to_blob('11111000011111000100001110000101010101000001000000011111100000000000000000111111111111100000000111111'),'comm');
end loop;
commit;
end;
/
--查詢佔用空間
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAME BYTES/1024
T_LOB_TEST 64
SYS_IL0000346640C00002$$ 128
SYS_LOB0000346640C00002$$ 9216
--刪除部分資料
SQL> delete from T_LOB_TEST where id>200;
800 rows deleted
SQL> commit;
Commit complete
SQL>
--再次查詢佔用空間,並未變化
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAME BYTES/1024
T_LOB_TEST 64
SYS_IL0000346640C00002$$ 128
SYS_LOB0000346640C00002$$ 9216
--再次插入資料
declare
i number(10);
begin
for i in 201..1000
loop
insert into T_LOB_TEST values(i,to_blob('11111000011111000100001110000101010101000001000000011111100000000000000000111111111111100000000111111'),'comm');
end loop;
commit;
end;
/
--再查詢佔用空間,發現佔用空間變大了
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST64
SYS_IL0000346640C00002$$192
SYS_LOB0000346640C00002$$15360
--結論1:
--lob欄位空間不會重複使用。重複刪除插入,lob欄位持續增長
--處理方法:需要壓縮空間
ALTER TABLE r_zhangry.T_LOB_TEST MODIFY LOB (xml_content) (SHRINK SPACE);
--查詢佔用空間,變成初始狀態了
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST64
SYS_IL0000346640C00002$$320
SYS_LOB0000346640C00002$$960
--測試2 測試非disable storage in row模式下
--該模式為預設模式,既小於4k的資料不會存在lob中,只有大於4k的資料才會存在lob欄位中
--建立測試表
create table T_LOB_TEST
(
id number(10) not null,
xml_content BLOB,
comm VARCHAR2(5)
)
;
--插入資料
declare
i number(10);
begin
for i in 1..1000
loop
if mod(i,3) != 0 then
insert into T_LOB_TEST values(i,to_blob('11111000011111000100001110000'),'comm');
else
insert into T_LOB_TEST (select i,b.payload,'comm' from mid_opr.JBM_MSG b where rownum<2);
end if;
commit;
end loop;
commit;
end;
/
--查詢佔用空間
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST128
SYS_IL0000346643C00002$$64
SYS_LOB0000346643C00002$$16384
--刪除部分資料
SQL> delete from T_LOB_TEST where id>200;
800 rows deleted
SQL> commit;
Commit complete
SQL>
--再次查詢佔用空間,並無變化
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST128
SYS_IL0000346643C00002$$64
SYS_LOB0000346643C00002$$16384
--再次插入資料
declare
i number(10);
begin
for i in 201..1000
loop
if mod(i,3) != 0 then
insert into T_LOB_TEST values(i,to_blob('11111000011111000100001110000'),'comm');
else
insert into T_LOB_TEST (select i,b.payload,'comm' from mid_opr.JBM_MSG b where rownum<2);
end if;
commit;
end loop;
commit;
end;
/
--再查詢佔用空間,佔用空間變大了
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST128
SYS_IL0000346643C00002$$64
SYS_LOB0000346643C00002$$29696
結論2:
--lob欄位空間不會重複使用。重複刪除插入,lob欄位持續增長
處理方法:
--需要壓縮空間
ALTER TABLE r_zhangry.T_LOB_TEST MODIFY LOB (xml_content) (SHRINK SPACE);
--再次查詢空間,結果變為初始狀態
select segment_name,bytes/1024 from user_segments where segment_name='T_LOB_TEST'
or segment_name in (select segment_name from user_lobs where table_name='T_LOB_TEST')
or segment_name in (select index_name from user_lobs where table_name='T_LOB_TEST');
SEGMENT_NAMEBYTES/1024
T_LOB_TEST128
SYS_IL0000346643C00002$$64
SYS_LOB0000346643C00002$$16384