分析HWM
下面結合官方文件和實驗介紹下HWM:
以下英文摘自11gR2官方文件:
HWM(high water mark):The boundary between used and unused space in a segment.
ORACLE9i之後開始使用自動段空間管理即ASSM,它使用點陣圖來管理段空間的使用情況,如果表空間ASSM,則表空間中的段也是ASSM.
At table creation, the HWM is at the beginning of the segment on the left. Because no data has been inserted yet, all blocks in the segment are unformatted and never used.
當表建立時,HWM開始於段的最左邊。因為從來沒有資料插入,所有在段裡的塊沒有被格式化和使用。
Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows. The allocated blocks fall below the HWM. The database formats a bitmap block in this group to hold the metadata, but does not preformat the remaining blocks in the group.In Figure 12–24, the blocks below the HWM are allocated, whereas blocks above the HWM are neither allocated or formatted. As inserts occur, the database can write to any block with available space. The low high water mark (low HWM) marks the point below which all blocks are known to be formatted because they either contain data or formerly contained data.
假設一個事務將行插入到段。資料庫必須分配一個組塊的行。低於HWM分配的塊。這組資料庫格式的點陣圖塊的後設資料,但不預先格式剩下的組塊。在圖12 - 24中,下面的塊HWM分配,而塊上面HWM既不分配或格式化。插入時,資料庫可以寫任何塊可用空間。高水標低(低HWM)標誌著點下面這所有的塊都被格式化的,因為他們要麼包含資料或以前包含資料。
In Figure 12–25, the database chooses a block between the HWM and low HWM and writes to it. The database could have just as easily chosen any other block between the HWM and low HWM, or any block below the low HWM that had available space. In Figure 12–25, the blocks to either side of the newly filled block are unformatted.
在圖12-25,資料庫選擇HWM和低HWM和之間的一塊寫道。資料庫也可以輕易選擇其他塊之間HWM和低HWM,或任何塊低於低HWM可用空間。在圖12-25,塊的新填充塊無格式。
The low HWM is important in a full table scan. Because blocks below the HWM arformatted only when used, some blocks could be unformatted, as in Figure 12–25. Fthis reason, the database reads the bitmap block to obtain the location of the low HWM. The database reads all blocks up to the low HWM because they are known tbe formatted, and then carefully reads only the formatted blocks between the low HWM and the HWM.Assume that a new transaction inserts rows into the table, but the bitmap indicates that insufficient free space exists under the HWM. In Figure 12–26, the database advances the HWM to the right, allocating a new group of unformatted blocks.
HWM低是重要的在一個全表掃描。因為塊低於HWM基於“增大化現實”技術格式化只使用時,一些街區可以無格式,如圖12-25所示。F因此,資料庫讀取點陣圖塊獲得低的位置HWM。資料庫讀取所有塊的低HWM因為它們是已知的被格式化,然後仔細閱讀只有格式化塊之間的低HWM HWM。假設一個新的事務將行插入到表中,但點陣圖顯示HWM空閒空間不足存在。圖12-26資料庫右邊的HWM進步,分配一個新組的非格式化塊。
When the blocks between the HWM and low HWM are full, the HWM advances to the right and the low HWM advances to the location of the old HWM. As the database inserts data over time, the HWM continues to advance to the right, with the low HWM always trailing behind it. Unless you manually rebuild, truncate, or shrink the object, the HWM never retreats.
當HWM之間的塊和低HWM充滿,HWM進步的正確的和低老HWM HWM進步的位置。作為資料庫插入資料隨著時間的推移,右邊的HWM不斷進步,HWM偏低總是落後。除非你手動重建、截斷或縮小物件,HWM從不撤退。
以上透過官方文件理論的分析了HWM,下面我們透過實驗來分析:
[oracle@localhost ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
SQL> show user;
USER 為 "HR"
SQL> desc t;
名稱 是否為空? 型別
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(10)
SQL> select count(*) from t;
COUNT(*)
----------
327680
SQL> exec dbms_stats.gather_table_stats('HR','T'); oracle提供了這個分析包
PL/SQL 過程已成功完成。
當然你也可以使用之前版本提供的工具:
SQL> analyze table t1 compute statistics;
表已分析。
表已分析。
上面的引數不一一介紹,感興趣的可以研究。
透過執行計劃分析:
SQL> set autotrace traceonly;
SQL> select * from t;(執行了兩次,此為第二次結果)
已選擇327680行。
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 327K| 2240K| 172 (2)| 00:00:03 |
| 1 | TABLE ACCESS FULL| T | 327K| 2240K| 172 (2)| 00:00:03 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
22418 consistent gets
0 physical reads
0 redo size
6379306 bytes sent via SQL*Net to client
240710 bytes received via SQL*Net from client
21847 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
327680 rows processed
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
從上面可以看出,邏輯讀了22418次。
我們此時delete表t,但是不會降低HWM:
表t雖然被delete的那部分被刪除,但是被佔用的那部分內空間存仍然沒被釋放,可以透過alter table t move來釋放儲存空間:
alter table move 主要有兩方面的作用:
表已更改。
此時rows的rowid也會改變。
SQL> select * from t; (執行了兩次,此為第二次結果)
已選擇131072行。
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 327K| 2240K| 172 (2)| 00:00:03 |
| 1 | TABLE ACCESS FULL| T | 327K| 2240K| 172 (2)| 00:00:03 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
1 recursive calls
0 db block gets
9274 consistent gets
0 physical reads
0 redo size
4020151 bytes sent via SQL*Net to client
96533 bytes received via SQL*Net from client
8740 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
131072 rows processed
但是此時造成建立在id上的索引不可用:
此時我們可以透過重建索引來解決:
alter index index_t rebuild (tablespace users) online;(此時如果不加online,則不能進行delete,update,insert操作,對於大表來說,很慢)
SQL> alter index index_t rebuild online;
索引已更改。
以下英文摘自11gR2官方文件:
HWM(high water mark):The boundary between used and unused space in a segment.
ORACLE9i之後開始使用自動段空間管理即ASSM,它使用點陣圖來管理段空間的使用情況,如果表空間ASSM,則表空間中的段也是ASSM.
At table creation, the HWM is at the beginning of the segment on the left. Because no data has been inserted yet, all blocks in the segment are unformatted and never used.
當表建立時,HWM開始於段的最左邊。因為從來沒有資料插入,所有在段裡的塊沒有被格式化和使用。
Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows. The allocated blocks fall below the HWM. The database formats a bitmap block in this group to hold the metadata, but does not preformat the remaining blocks in the group.In Figure 12–24, the blocks below the HWM are allocated, whereas blocks above the HWM are neither allocated or formatted. As inserts occur, the database can write to any block with available space. The low high water mark (low HWM) marks the point below which all blocks are known to be formatted because they either contain data or formerly contained data.
假設一個事務將行插入到段。資料庫必須分配一個組塊的行。低於HWM分配的塊。這組資料庫格式的點陣圖塊的後設資料,但不預先格式剩下的組塊。在圖12 - 24中,下面的塊HWM分配,而塊上面HWM既不分配或格式化。插入時,資料庫可以寫任何塊可用空間。高水標低(低HWM)標誌著點下面這所有的塊都被格式化的,因為他們要麼包含資料或以前包含資料。
In Figure 12–25, the database chooses a block between the HWM and low HWM and writes to it. The database could have just as easily chosen any other block between the HWM and low HWM, or any block below the low HWM that had available space. In Figure 12–25, the blocks to either side of the newly filled block are unformatted.
在圖12-25,資料庫選擇HWM和低HWM和之間的一塊寫道。資料庫也可以輕易選擇其他塊之間HWM和低HWM,或任何塊低於低HWM可用空間。在圖12-25,塊的新填充塊無格式。
The low HWM is important in a full table scan. Because blocks below the HWM arformatted only when used, some blocks could be unformatted, as in Figure 12–25. Fthis reason, the database reads the bitmap block to obtain the location of the low HWM. The database reads all blocks up to the low HWM because they are known tbe formatted, and then carefully reads only the formatted blocks between the low HWM and the HWM.Assume that a new transaction inserts rows into the table, but the bitmap indicates that insufficient free space exists under the HWM. In Figure 12–26, the database advances the HWM to the right, allocating a new group of unformatted blocks.
HWM低是重要的在一個全表掃描。因為塊低於HWM基於“增大化現實”技術格式化只使用時,一些街區可以無格式,如圖12-25所示。F因此,資料庫讀取點陣圖塊獲得低的位置HWM。資料庫讀取所有塊的低HWM因為它們是已知的被格式化,然後仔細閱讀只有格式化塊之間的低HWM HWM。假設一個新的事務將行插入到表中,但點陣圖顯示HWM空閒空間不足存在。圖12-26資料庫右邊的HWM進步,分配一個新組的非格式化塊。
When the blocks between the HWM and low HWM are full, the HWM advances to the right and the low HWM advances to the location of the old HWM. As the database inserts data over time, the HWM continues to advance to the right, with the low HWM always trailing behind it. Unless you manually rebuild, truncate, or shrink the object, the HWM never retreats.
當HWM之間的塊和低HWM充滿,HWM進步的正確的和低老HWM HWM進步的位置。作為資料庫插入資料隨著時間的推移,右邊的HWM不斷進步,HWM偏低總是落後。除非你手動重建、截斷或縮小物件,HWM從不撤退。
以上透過官方文件理論的分析了HWM,下面我們透過實驗來分析:
[oracle@localhost ~]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
SQL> show user;
USER 為 "HR"
SQL> desc t;
名稱 是否為空? 型別
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(10)
SQL> select count(*) from t;
COUNT(*)
----------
327680
t是使用者hr裡的一張比較大的表。
我們在列id上建索引index_t:(下面有用)
SQL> create index index_t on t(id);
索引已建立。
分析一下表:我們在列id上建索引index_t:(下面有用)
SQL> create index index_t on t(id);
索引已建立。
SQL> exec dbms_stats.gather_table_stats('HR','T'); oracle提供了這個分析包
PL/SQL 過程已成功完成。
當然你也可以使用之前版本提供的工具:
SQL> analyze table t1 compute statistics;
表已分析。
刪除分析:
SQL> analyze table t1 delete statistics;表已分析。
Total Blocks 表示分配給表的總的blocks 數。
Unused Blocks 表示位於高水位線以上的從未使用的資料塊個數。
透過執行計劃分析:
SQL> set autotrace traceonly;
SQL> select * from t;(執行了兩次,此為第二次結果)
已選擇327680行。
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 327K| 2240K| 172 (2)| 00:00:03 |
| 1 | TABLE ACCESS FULL| T | 327K| 2240K| 172 (2)| 00:00:03 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
0 recursive calls
0 db block gets
22418 consistent gets
0 physical reads
0 redo size
6379306 bytes sent via SQL*Net to client
240710 bytes received via SQL*Net from client
21847 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
327680 rows processed
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
從上面可以看出,邏輯讀了22418次。
我們此時delete表t,但是不會降低HWM:
表t雖然被delete的那部分被刪除,但是被佔用的那部分內空間存仍然沒被釋放,可以透過alter table t move來釋放儲存空間:
alter table move 主要有兩方面的作用:
1、用來移動table 到其他表空間。
2、用來減少table 中的儲存碎片,最佳化儲存空間和效能。
SQL> alter table t move (tablespace users) online;(此時別的會話可以正常訪問此表)表已更改。
此時rows的rowid也會改變。
SQL> select * from t; (執行了兩次,此為第二次結果)
已選擇131072行。
執行計劃
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 327K| 2240K| 172 (2)| 00:00:03 |
| 1 | TABLE ACCESS FULL| T | 327K| 2240K| 172 (2)| 00:00:03 |
--------------------------------------------------------------------------
統計資訊
----------------------------------------------------------
1 recursive calls
0 db block gets
9274 consistent gets
0 physical reads
0 redo size
4020151 bytes sent via SQL*Net to client
96533 bytes received via SQL*Net from client
8740 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
131072 rows processed
此時的邏輯讀已經降低為9274。
但是此時造成建立在id上的索引不可用:
此時我們可以透過重建索引來解決:
alter index index_t rebuild (tablespace users) online;(此時如果不加online,則不能進行delete,update,insert操作,對於大表來說,很慢)
SQL> alter index index_t rebuild online;
索引已更改。
索引重新可以使用:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29876893/viewspace-1579918/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle HWMOracle
- Oracle 之HWMOracle
- Oracle 高水位(HWM)Oracle
- Show_HWM.sqlSQL
- ORACLE FREELIST HWM(轉)Oracle
- ORACLE 高水位線(HWM)Oracle
- ORACLE FREELIST HWM(3)Oracle
- ORACLE FREELIST HWM(2)Oracle
- ORACLE FREELIST HWM(1)Oracle
- hwm的一點理解
- oracle的高水位線HWMOracle
- oracle的高水位線(HWM)Oracle
- Oracle 高水位(HWM)標記Oracle
- delete與高水位線HWM回收delete
- Oracle表段中高水位線HWMOracle
- HWM下被使用了的block佔hwm下所有block的百分比計算!BloC
- oracle10g shrink space 降低HWMOracle
- HWM和delete,drop,truncate的關係delete
- 深入瞭解oracle的高水位(HWM)Oracle
- Oracle高水位線(HWM)及效能優化Oracle優化
- Oracle表段中的高水位線HWMOracle
- Oracle效能調優之FreeList和HWMOracle
- Oracle效能調優 之FreeList和HWMOracle
- Oracle Freelist和HWM的效能優化Oracle優化
- Oracle案例10——HWM(高水位線)效能優化Oracle優化
- 轉:Oracle Freelist和HWM的效能優化Oracle優化
- Oracle段高水位(HWM, high water mark)問題Oracle
- 各個Oracle 版本下如何調整高水位(HWM)Oracle
- Oracle中 HWM與資料庫效能的探討Oracle資料庫
- Oracle Freelist和HWM原理及效能最佳化(轉)Oracle
- actual size LOB segments and free deleted/unused space above/below HWM-386341.1delete
- 【實驗】關於HWM(高水位)的學習與測試
- zt_eygle_Oracle中 HWM與資料庫效能的探討Oracle資料庫
- Oracle Freelist和HWM原理探討及相關效能優化Oracle優化
- Oracle Freelist和HWM原理探討及相關效能優化(轉)Oracle優化
- Oracle Freelist和HWM原理探討及相關效能最佳化Oracle
- Oracle Freelist和HWM原理探討及相關效能最佳化(1)Oracle
- Oracle Freelist和HWM原理探討及相關效能最佳化(2)Oracle