SQL> delete from test_1 where rownum <=1;
1 row deleted.
SQL> delete from test_2 where rownum <=1;
1 row deleted.
SQL> exec dbms_stats.gather_table_stats(ownname =>'ADMIN',tabname =>'TEST_1',cascade=>TRUE);
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(ownname =>'ADMIN',tabname =>'TEST_2',cascade=>TRUE);
PL/SQL procedure successfully completed.
SQL> select TABLE_NAME,BLOCKS,EMPTY_BLOCKS from user_tables where table_name in ('TEST_1','TEST_2');
TABLE_NAME BLOCKS EMPTY_BLOCKS
------------------------------ ---------- ------------
TEST_1 222 0
TEST_2 222 0
SQL> select B.SEGMENT_NAME, B.blocks,B.blocks * 8096 / 1024 / 1024, A.BLOCKS,A.blocks * 8096 / 1024 / 1024, A.EMPTY_BLOCKS from user_tables a,
2 USER_SEGMENTS B WHERE TABLE_NAME in ('TEST_1','TEST_2') AND A.TABLE_NAME = B.SEGMENT_NAME;
SEGMENT_NAME BLOCKS B.BLOCKS*8096/1024/1024 BLOCKS A.BLOCKS*8096/1024/1024 EMPTY_BLOCKS
--------------------------------------------------------------------------------- ---------- ----------------------- ---------- ----------------------- ------------
TEST_1 64512 498.09375 222 1.71405029 0
TEST_2 64512 498.09375 222 1.71405029 0
SQL>
SQL> select index_name,table_name,status from user_indexes where table_name in ('TEST_1','TEST_2'); ---此时索引状态都正常
INDEX_NAME TABLE_NAME STATUS
------------------------------ ------------------------------ --------
IDX_TEST2 TEST_2 VALID
IDX_TEST1 TEST_1 VALID
---从上面可以看出,虽然删除了表的数据,但是空间并没有释放,没有释放的空间包括高水位线以上和高水位线以下。(高水位线上面的空间就是预分配的空间 减去 实际占用的空间;
高水位线以下的空间就是数据实际占用的空间--因为delete是不会是否空间的,也就是说高水位一直存在除非新插入的数据将其覆盖)
5、对test_1表进行move操作:
SQL> alter table test_1 move;
Table altered.
SQL> exec dbms_stats.gather_table_stats(ownname =>'ADMIN',tabname =>'TEST_1',cascade=>TRUE);
PL/SQL procedure successfully completed.
SQL> select B.SEGMENT_NAME, B.blocks,B.blocks * 8096 / 1024 / 1024, A.BLOCKS,A.blocks * 8096 / 1024 / 1024, A.EMPTY_BLOCKS from user_tables a,
2 USER_SEGMENTS B WHERE TABLE_NAME in ('TEST_1','TEST_2') AND A.TABLE_NAME = B.SEGMENT_NAME;
SEGMENT_NAME BLOCKS B.BLOCKS*8096/1024/1024 BLOCKS A.BLOCKS*8096/1024/1024 EMPTY_BLOCKS
--------------------------------------------------------------------------------- ---------- ----------------------- ---------- ----------------------- ------------
TEST_2 64512 498.09375 222 1.71405029 0
TEST_1 64384 497.105469 35 .270233154 0
SQL> select index_name,table_name,status from user_indexes where table_name in ('TEST_1','TEST_2');
INDEX_NAME TABLE_NAME STATUS
------------------------------ ------------------------------ --------
IDX_TEST2 TEST_2 VALID
IDX_TEST1 TEST_1 UNUSABLE