1. SQL> select * from v$version;

  2. BANNER
  3. ----------------------------------------------------------------

  4. Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
  5. PL/SQL Release 10.2.0.1.0 - Production
  6. CORE 10.2.0.1.0 Production
  7. TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
  8. NLSRTL Version 10.2.0.1.0 - Production

  9.  

  10.  

  11. ---1.创建测试表

  12. CREATE TABLE T1 TABLESPACE TEST AS SELECT * FROM DBA_OBJECTS;

  13. --2 查询segment 头块

  14. SQL> SELECT HEADER_FILE,HEADER_BLOCK FROM DBA_SEGMENTS WHERE SEGMENT_NAME = 'T1';

  15. HEADER_FILE HEADER_BLOCK
  16. ----------- ------------

  17.          22 795

  18. --3 DUMP segment 头块


  19. ALTER SYSTEM DUMP DATAFILE 22 BLOCK 795;

  20. --4 查看结尾为2492的trace文件 (ORAHOME\product\10.2.0\admin\orcl\udump)


  21. SELECT SPID
  22.   FROM V$PROCESS
  23.  WHERE ADDR = (SELECT PADDR
  24.                  FROM V$SESSION
  25.                 WHERE SID = (SELECT DISTINCT SID FROM V$MYSTAT));
  26. SPID
  27. ------------

  28. 2492

  29. --HWM 为 0x058008fb

  30. Highwater:: 0x058008fb

  31. --5 计算HWM 对应的文件编号和块

  32. SQL> SELECT DBMS_UTILITY.DATA_BLOCK_ADDRESS_FILE(TO_NUMBER('058008FB','XXXXXXXX')) AS HWM_FILEID FROM DUAL;

  33. HWM_FILEID
  34. ----------

  35.         22

  36. SQL> SELECT DBMS_UTILITY.DATA_BLOCK_ADDRESS_BLOCK(TO_NUMBER('058008FB','XXXXXXXX')) AS HWM_BLOCKID FROM DUAL;

  37. HWM_BLOCKID
  38. -----------

  39.        2299
  40.        
  41. --6. 分析表,查看sgemnt空块的数及最大使用的Block ID

  42. SQL> SELECT FILE_ID,MIN(BLOCK_ID),MAX(BLOCK_ID+BLOCKS) FROM DBA_EXTENTS WHERE SEGMENT_NAME='T1' GROUP BY FILE_ID;

  43.    FILE_ID MIN(BLOCK_ID) MAX(BLOCK_ID+BLOCKS)
  44. ---------- ------------- --------------------

  45.         22 793 2313
  46.         
  47. ANALYZE TABLE T1 COMPUTE STATISTICS;

  48. SQL> SELECT EMPTY_BLOCKS FROM DBA_TABLES WHERE TABLE_NAME = 'T1';

  49. EMPTY_BLOCKS
  50. ------------

  51.           14
  52. SQL> SELECT 2313 -14 FROM DUAL;--等于HWM_BLOCKID


  53.    2313-14
  54. ----------

  55.       2299
  56. --7.记录下delete数据前count(*)的统计信息

  57. SQL> set autotrace traceonly;
  58. SQL> select count(*) from T1;


  59. 执行计划
  60. ----------------------------------------------------------

  61. Plan hash value: 3724264953

  62. -------------------------------------------------------------------
  63. | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |   
  64. -------------------------------------------------------------------   
  65. |   0 | SELECT STATEMENT   |      |     1 |   169   (2)| 00:00:03 |   
  66. |   1 |  SORT AGGREGATE    |       |     1 |            |          |   
  67. |   2 |   TABLE ACCESS FULL| T1   | 53176 |   169   (2)| 00:00:03 |  
  68. -------------------------------------------------------------------



  69. 统计信息
  70. ----------------------------------------------------------

  71.           0 recursive calls
  72.           0 db block gets
  73.         739 consistent gets
  74.           0 physical reads
  75.           0 redo size
  76.         410 bytes sent via SQL*Net to client
  77.         385 bytes received via SQL*Net from client
  78.           2 SQL*Net roundtrips to/from client
  79.           0 sorts (memory)
  80.           0 sorts (disk)
  81.           1 rows processed

  82. --8 删除数据

  83. SQL> set autotrace off;
  84. SQL> select count(*) from T1;

  85.   COUNT(*)
  86. ----------

  87.      53176
  88.      
  89. SQL> delete T1 where rownum <= 30000;

  90. 已删除30000行。

  91. SQL> COMMIT;

  92. 提交完成。

  93. --9 重新dump 数据头,发现Highwater仍然是原来的值。说明DELETE 并不能使HWM下降。

  94. ALTER SYSTEM DUMP DATAFILE 22 BLOCK 795;

  95. Highwater:: 0x058008fb

  96. --10. 分析删除数据后,count(*)的统计信息,发现执行的消耗与删除前一样。739个逻辑读

  97. SQL> set autotrace on;
  98. SQL> select count(*) from T1;

  99.   COUNT(*)
  100. ----------

  101.      23176


  102. 执行计划
  103. ----------------------------------------------------------

  104. Plan hash value: 3724264953

  105. -------------------------------------------------------------------
  106. | Id  | Operation          | Name | Rows  | Cost (%CPU)| Time     |   
  107. -------------------------------------------------------------------   
  108. |   0 | SELECT STATEMENT   |      |     1 |   169   (2)| 00:00:03 |   
  109. |   1 |  SORT AGGREGATE     |      |     1 |            |          |   
  110. |   2 |   TABLE ACCESS FULL| T1   | 23176 |   169   (2)| 00:00:03 |
  111. -------------------------------------------------------------------



  112. 统计信息
  113. ----------------------------------------------------------

  114.           0 recursive calls
  115.           0 db block gets
  116.         739 consistent gets
  117.           0 physical reads
  118.           0 redo size
  119.         410 bytes sent via SQL*Net to client
  120.         385 bytes received via SQL*Net from client
  121.           2 SQL*Net roundtrips to/from client
  122.           0 sorts (memory)
  123.           0 sorts (disk)
  124.           1 rows processed

09-02 06:53