原创 转载请注明出处
下面的例子只是证明空间的重用
create table pp
as
select * from dba_tables,dba_users;
execute dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'pp');
SQL> select BLOCKS from dba_tab_statistics where table_name='PP' and wner='SYS';
BLOCKS
-----------
1513
SQL> select min(BLOCK_ID) from dba_extents where SEGMENT_NAME='PP' and wner='SYS';
MIN(BLOCK_ID)
-------------
66073
SQL> select max(BLOCK_ID) from dba_extents where SEGMENT_NAME='PP';
MAX(BLOCK_ID)
-------------
67977
SQL> select BLOCK_ID+BLOCKS from dba_extents where SEGMENT_NAME='PP' and wner='SYS' and BLOCK_ID= 67977;
BLOCK_ID+BLOCKS
---------------
68105
所以占用空间块区间是66073到68105
然后截断表
SQL> truncate table pp;
SQL> execute dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'pp');
PL/SQL procedure successfully completed
SQL> select min(BLOCK_ID) from dba_extents where SEGMENT_NAME='PP' and wner='SYS';
MIN(BLOCK_ID)
-------------
66073
SQL> select max(BLOCK_ID) from dba_extents where SEGMENT_NAME='PP';
MAX(BLOCK_ID)
-------------
66073
实际这些只是占用了一个EXTENT,但是下一个分区却是从66097开始的,我也不知道为何是SEGMENTS头的原因吧。这时的区间而66073到66097,当然HWM也下降了,使用的块为0
然后
SQL> create table oo
2 as
3 select * from dba_tables,dba_users;
SQL> select min(BLOCK_ID) from dba_extents where SEGMENT_NAME='OO' and wner='SYS';
MIN(BLOCK_ID)
-------------
66097
SQL> select MAX(BLOCK_ID) from dba_extents where SEGMENT_NAME='OO' and wner='SYS';
MAX(BLOCK_ID)
-------------
67977
这里OO的区间实际是66097到67977+128。
这里明显重用的空间。基本都重用了。
所以TRUNCATE的空间是会被新的段运用的