首先创建两个测试表test,test1
两个表数据放在data_tablespace,索引放在index_tablespace表空间下(测试证明和表空间没有关系)
如果使用下面两个语句删除两个表中的数据truncate table test drop storage;
truncate table test1 reuse storage;
得到的结果将会是:
test表中的data:数据所在的extent空间被释放,释放的空间可以供其它segment使用;
test表中的index:数据删除,剩下第一个extent;
test表的hwm:重新设置到第一个block的位置(hwm会改变);
test1表中的data:数据所在的extent空间不会被回收(仅仅数据会被删除),数据删除之后的freespace空间只能供本表使用,不可以供其它segment使用;
test1表中的index:数据删除,但是保留extent;
test1表的hwm:重新设置到第一个block的位置(hwm会改变);
测试开始:
create table test (name varchar2(20));
insert into test values('a');
create table test1 as select * from test;
create index ind_test1 on test1(name);
查看一下四个段对extent的使用
select segment_name,extent_id,bytes from user_extents where segment_name like '%TEST%' order by 1;
对表进行分析,否则下面的语句没结果
analyze table test compute statistics;
analyze table test1 compute statistics;col table_name format a10
SELECT TABLE_NAME,blocks,empty_blocks,blocks-empty_blocks hwm FROM user_tables WHERE table_name IN ('TEST','TEST1');
set pagesize 10
查看test,test1表的HWM,计算公式HWM=total_blocks-empty_blocks,可以看到test,test1的HWM是38
truncate table test drop storage;
truncate table test1 reuse storage;
select segment_name,extent_id,bytes from user_extents where segment_name like '%TEST%' order by 1;
可以看到test表本身及其索引idx_test的extent都是释放的,都保留到第一个extent
analyze table test compute statistics;
analyze table test1 compute statistics;SELECT TABLE_NAME,blocks,empty_blocks,blocks-empty_blocks hwm FROM user_tables WHERE table_name IN ('TEST','TEST1');
可以看到两个表的hwm都回到了第一个block