posts - 75,comments - 83,trackbacks - 0

我做的小实验,LZ参考看看
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as ljb
SQL> drop table test;
Table dropped
SQL> create table test tablespace cdma as select * from dba_objects;
Table created
查看一下该表大小,为8388608个字节
SQL> select segment_name,bytes,tablespace_name from user_segments where segment_name='TEST';
SEGMENT_NAME BYTES TABLESPACE_NAME
------------------------------- -----------------------------------------------------
TEST 8388608 CDMA
SQL> delete from test;
62654 rows deleted
SQL> commit;
Commit complete
确实,发现删除提交后,表大小仍然为8388608个字节个字节,并没释放,此时如果查询该表记录,虽然有记录,但是和刚才没记录查询一样慢,这点在前面已经说过了。
SQL> select segment_name,bytes,tablespace_name from user_segments where segment_name='TEST';
SEGMENT_NAME BYTES TABLESPACE_NAME
------------------------------- -----------------------------------------------------
TEST 8388608 CDMA
                         
那如果再次插入呢?是否空间大小是8388608的两倍呢?
SQL> insert into test select * from dba_objects;
62654 rows inserted
SQL> commit;
Commit complete
惊奇的发现,大小仍然一样
SQL> select segment_name,bytes,tablespace_name from user_segments where segment_name='TEST';
SEGMENT_NAME BYTES TABLESPACE_NAME
------------------------------- -----------------------------------------------------
TEST 8388608 CDMA
下面用另外一个方式来查看,show_space是显示表详细情况的过程
SQL> set serverout on
SQL> exec show_space('TEST','auto');

Total Blocks............................1024
Total Bytes.............................8388608
Unused Blocks...........................125
Unused Bytes............................1024000
Last Used Ext FileId....................77
Last Used Ext BlockId...................820489
Last Used Block.........................3

PL/SQL procedure successfully completed

SQL> delete from test;
62654 rows deleted
SQL> commit;
删除再次插入,仍然大小一样,而且所有的细项都保持不变!
Commit complete
SQL> exec show_space('TEST','auto');

Total Blocks............................1024
Total Bytes.............................8388608
Unused Blocks...........................125
Unused Bytes............................1024000
Last Used Ext FileId....................77
Last Used Ext BlockId...................820489
Last Used Block.........................3
PL/SQL procedure successfully completed
总结:delete是不能立即释放空间,但是却是可以被重用,也就是某个应用经常删除再经常插入,并不会有太多的空块!对于频繁插入和更新的表,运行慢,不该怀疑是因为里面有太多空块。
posted on 2009-12-08 14:20 梓枫 阅读(227) 评论(0)  编辑  收藏 所属分类: oracle

只有注册用户登录后才能发表评论。


网站导航: