降低高水位线

1、建立初始化数据演示数据表中的高水位的变化

(1)、建立用户和表

SYS@odb>create user test8 identified by test8;

SYS@odb>grant connect,resource to test8;

SYS@odb>conn test8/test8

TEST8@odb>create table gaoshuiwei as select * from all_objects;

TEST8@odb>select TABLE_NAME,NUM_ROWS,BLOCKS from user_tables where table_name='GAOSHUIWEI';

TABLE_NAME NUM_ROWS BLOCKS

---------------------------------------- ----------

GAOSHUIWEI 68309 500

TEST8@odb>delete from gaoshuiwei;

TEST8@odb>commit;

TEST8@odb>select count(*) from gaoshuiwei;

COUNT(*)

----------

0

TEST8@odb>select TABLE_NAME,BLOCKS from user_tables wheretable_name='GAOSHUIWEI';

TABLE_NAME NUM_ROWS BLOCKS

---------------------------------------- ----------

GAOSHUIWEI 68309 500

可以看到在删除表中的数据后,在user_tables里面该表还是有68309行和500个快大约8M左右;

(2)、在次插入数据

TEST8@ odb>insert intogaoshuiwei select * from all_objects;

TEST8@ odb>commit;

TEST8@ odb>select count(*) fromgaoshuiwei;

COUNT(*)

----------

68309

TEST8@ odb>selectTABLE_NAME,BLOCKS from user_tables where table_name='GAOSHUIWEI';

TABLE_NAME NUM_ROWS BLOCKS

---------------------------------------- ----------

GAOSHUIWEI 68309500

TEST8@ odb>delete fromgaoshuiwei;

68309 rows deleted.

TEST8@ odb>commit;

Commit complete.

TEST8@ odb>selectTABLE_NAME,BLOCKS from user_tables where table_name='GAOSHUIWEI';

TABLE_NAME NUM_ROWS BLOCKS

---------------------------------------- ----------

GAOSHUIWEI 68309 500

看到信息没什么变化,需要搜集统计信息;

TEST8@odb>

execdbms_stats.gather_table_stats('TEST8','GAOSHUIWEI',cascade=>true);

PL/SQL procedure successfullycompleted.

TEST8@ odb>selectTABLE_NAME,BLOCKS from user_tables where table_name='GAOSHUIWEI';

TABLE_NAME NUM_ROWS BLOCKS

---------------------------------------- ----------

GAOSHUIWEI 0 500

TEST8@ odb>selectsegment_name,segment_type,bytes from user_segments wheresegment_name='GAOSHUIWEI'; //查看段的信息

SEGMENT_NAME SEGMENT_TYPE BYTES

-------------------------------------- ----------

GAOSHUIWEI TABLE 8388608

块500 大约8M左右, 生成执行计划:

TEST8@odb>explain plan for select count(*) from gaoshuiwei;

Explained.

TEST8@odb>select * from table(dbms_xplan.display);

该表是0行数据 ,全表扫描,cost 189 ;原因是因为的该表来回的插入删除,高水位线一直没有降下来,还会扫描500个块,全部扫描一遍返回结果,如果发现表的数据不大,但是查询很慢,可能和高水位有关

可采用

方法(1)、使用truncate 方法

方法(2)、使用移动表空间的方法

方法(3)、使用收缩表空间的方法

TEST8@ odb>alter table gaoshuiwei enablerow movement; //启用行移动

TEST8@ odb>alter table gaoshuiwei shrinkspace compact; //压缩表的空间,这时还没发生变化

TEST8@ odb>alter table gaoshuiwei shrinkspace; //降低表的高水位线这时变化就比较明显了

对索引也可以设置同样的操作

alter indexPUB_LOG_PK shrink space compact;

相关文章

文章浏览阅读773次,点赞6次,收藏9次。【代码】c# json字符...
文章浏览阅读8.7k次,点赞2次,收藏17次。此现象一般定位到远...
文章浏览阅读2.8k次。mysql脚本转化为oracle脚本_mysql建表语...
文章浏览阅读2.2k次。cx_Oracle报错:cx_Oracle DatabaseErr...
文章浏览阅读1.1k次,点赞38次,收藏35次。本文深入探讨了Or...
文章浏览阅读1.5k次。默认自动收集统计信息的时间为晚上10点...