表空间和数据文件实验三 高水位HWM相关知识以及降低HWM方法
下面是一个HWM的实验,HWM是指在一个段中已使用和未使用的BLOCK的分界线。HWM下面的空间是已经使用的或曾经使用过的,就是说HWM下面有已经使用的空间也有使用过而现在处于空闲状态的空间;HWM上面是未格式化(unformatted)的空间。
下面是跟踪一个块所得到的HWM的描述:
SQL> alter system dump datafile 4 block 553;
buffer tsn: 4 rdba: 0x01000229 (4/553)
HWM Flag: HWM Set
Highwater:: 0x01000231 ext#: 0 blk#: 8 ext size: 8
0:Metadata 1:Metadata 2:Metadata 3:FULL
4:75-100% free 5:75-100% free 6:FULL 7:75-100% free
8:unformatted 9:unformatted 10:unformatted 11:unformatted
12:unformatted 13:unformatted 14:unformatted 15:unformatted
上面的Highwater:: 0x01000231就是unformatted的第一个位置,上面可以看到是8:unformatted 前的数据已经使用。8的地址是当前地址0x01000229+7=0x01000231。
实验:对一个表进行删除,看数据的查询变化情况。
SQL> set autotrace on;
SQL> create table scott.test1 as select * from dba_objects;
表已创建。
SQL> select count(*) from scott.test1;
COUNT(*)
----------
50739
SQL> set autotrace on;
SQL> select count(*) from scott.test1;
COUNT(*)
----------
50739
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
702 consistent gets
0 physical reads
0 redo size
702 consistent gets 为全表扫描的次数。
SQL> delete from scott.test1 where rownum <3001;
已删除3000行。
SQL> commit;
提交完成。
SQL> select count(*) from scott.test1;
COUNT(*)
----------
47739
统计信息
0 recursive calls
0 db block gets
702 consistent gets
0 physical reads
0 redo size
SQL> delete from scott.test1 where rownum <30001;
已删除30000行。
SQL> commit;
提交完成。
SQL> select count(*) from scott.test1;
COUNT(*)
----------
17739
统计信息
0 recursive calls
0 db block gets
702 consistent gets
0 physical reads
0 redo size
发现删除了33000条记录,可仍是 702 consistent gets
SQL> SET AUTOTRACE OFF;
SQL> DELETE FROM SCOTT.TEST1 WHERE ROWNUM<40001;
已删除17739行。
SQL> COMMIT;
SQL> set autotrace on;
SQL> select count(*) from scott.test1;
COUNT(*)
----------
0
统计信息
----------------------------------------------------------
262 recursive calls
0 db block gets
733 consistent gets
0 physical reads
0 redo size
数据已经全部删除,可仍执行733 consistent gets 。
对表进行shrink后,全扫描明显降低:
SQL> alter table scott.test1 enable row movement;
表已更改。
SQL> alter table scott.test1 shrink space;
表已更改。
SQL> select count(*) from scott.test1;
COUNT(*)
----------
0
统计信息
----------------------------------------------------------
175 recursive calls
0 db block gets
20 consistent gets
1 physical reads
0 redo size
降到20次。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22528444/viewspace-683443/ ,如需转载,请注明出处,否则将追究法律责任。