[Oracle] Shrink space & Table move比較
本實驗是對兩個一樣的table,測試shrink space 和 table move釋放了多少空間,以及對index status的影響.
1.新建了兩個一樣的table tt5,tt7
SQL> select (select count(*) from tt5) tt5_count,(select count(*) from tt7) tt7_count from dual;
TT5_COUNT TT7_COUNT
---------- ----------
2619392 2619392
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 301989888
TT7 301989888
2.delete 一定量的資料
SQL> select (select count(*) from tt5 where object_id>25000) delcount,(select count(*) from tt7 where object_id>25000) delcount from dual;
DELCOUNT DELCOUNT
---------- ----------
1393408 1393408
SQL> delete from tt5 where object_id>25000;
1393408 rows deleted.
SQL> delete from tt7 where object_id>25000;
1393408 rows deleted.
SQL> commit;
Commit complete.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 301989888
TT7 301989888
SQL> select (select count(*) from tt5) tt5_count,(select count(*) from tt7) tt7_count from dual;
TT5_COUNT TT7_COUNT
---------- ----------
1225984 1225984
tt5,tt7 的segment大小沒有變化
4.對tt5,tt7分別進行table move,shrink space
SQL> alter table tt5 move;
Table altered.
SQL> alter table tt7 shrink space;
alter table tt7 shrink space
*
ERROR at line 1:
ORA-10636: ROW MOVEMENT is not enabled
SQL> alter table tt7 enable row movement;
Table altered.
SQL> alter table tt7 shrink space;
Table altered.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 142606336
TT7 131530752
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
-------------------------------- ----------
TT5_INDEX UNUSABLE
TT7_INDEX VALID
上面可以看出shrink space比table move更加縮小空間(差距很小),table move會將index status置為unusable
5.tt7 disable row movement
SQL> alter table tt7 disable row movement;
Table altered.
6.對tt7進行move後,tt5,tt7兩個table的大小一樣了。為啥shrink space&table move不一樣呢,奇怪...
SQL> alter table tt7 move;
Table altered.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 142606336
TT7 142606336
7.重新rebuild index
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
----------------------- ----------------
TT5_INDEX UNUSABLE
TT7_INDEX UNUSABLE
SQL> alter index tt5_index rebuild;
Index altered.
SQL> alter index tt7_index rebuild;
Index altered.
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
--------------------- ----------------
TT5_INDEX VALID
TT7_INDEX VALID
1.新建了兩個一樣的table tt5,tt7
SQL> select (select count(*) from tt5) tt5_count,(select count(*) from tt7) tt7_count from dual;
TT5_COUNT TT7_COUNT
---------- ----------
2619392 2619392
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 301989888
TT7 301989888
2.delete 一定量的資料
SQL> select (select count(*) from tt5 where object_id>25000) delcount,(select count(*) from tt7 where object_id>25000) delcount from dual;
DELCOUNT DELCOUNT
---------- ----------
1393408 1393408
SQL> delete from tt5 where object_id>25000;
1393408 rows deleted.
SQL> delete from tt7 where object_id>25000;
1393408 rows deleted.
SQL> commit;
Commit complete.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 301989888
TT7 301989888
SQL> select (select count(*) from tt5) tt5_count,(select count(*) from tt7) tt7_count from dual;
TT5_COUNT TT7_COUNT
---------- ----------
1225984 1225984
tt5,tt7 的segment大小沒有變化
4.對tt5,tt7分別進行table move,shrink space
SQL> alter table tt5 move;
Table altered.
SQL> alter table tt7 shrink space;
alter table tt7 shrink space
*
ERROR at line 1:
ORA-10636: ROW MOVEMENT is not enabled
SQL> alter table tt7 enable row movement;
Table altered.
SQL> alter table tt7 shrink space;
Table altered.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 142606336
TT7 131530752
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
-------------------------------- ----------
TT5_INDEX UNUSABLE
TT7_INDEX VALID
上面可以看出shrink space比table move更加縮小空間(差距很小),table move會將index status置為unusable
5.tt7 disable row movement
SQL> alter table tt7 disable row movement;
Table altered.
6.對tt7進行move後,tt5,tt7兩個table的大小一樣了。為啥shrink space&table move不一樣呢,奇怪...
SQL> alter table tt7 move;
Table altered.
SQL> select segment_name,bytes from user_segments where segment_name in('TT5','TT7');
SEGMENT_NAME BYTES
-------------------- ----------
TT5 142606336
TT7 142606336
7.重新rebuild index
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
----------------------- ----------------
TT5_INDEX UNUSABLE
TT7_INDEX UNUSABLE
SQL> alter index tt5_index rebuild;
Index altered.
SQL> alter index tt7_index rebuild;
Index altered.
SQL> select index_name,status from user_indexes where table_name in('TT5','TT7');
INDEX_NAME STATUS
--------------------- ----------------
TT5_INDEX VALID
TT7_INDEX VALID
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2055438/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- alter table move與shrink space
- Oracle move和shrink釋放高水位空間Oracle
- 比較兩個table是否相同
- [20190918]shrink space與ORA-08102錯誤.txt
- Oracle date 型別比較和String比較Oracle型別
- [重慶思莊每日技術分享]-在為表新增了列後執行ALTER TABLE SHRINK SPACE 提示ORA-8102
- admin_move_table線上更改分割槽鍵
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- Oracle table selectOracle
- Oracle:TABLE MONITORINGOracle
- 【SHRINK】Oracle收縮表的詳細命令參考Oracle
- DB2常用函式與Oracle比較TIDB2函式Oracle
- js 深比較和淺比較JS
- oracle cache table(轉)Oracle
- Oracle Pipelined Table(轉)Oracle
- Oracle vs PostgreSQL,研發注意事項(8)- Oracle資料比較規則OracleSQL
- Rename or Move a datafile In Oracle 19c RAC-20220117Oracle
- Oracle 12.2 新特性: Online PDB relocate (PDB hot move)Oracle
- Oracle Pipelined Table Functions(轉)OracleFunction
- 比較集合
- Integer比較
- 效能比較
- 字串比較字串
- Oracle資料庫管理——表資料庫高水位及shrink操作Oracle資料庫
- 相容oracle的edit_distance_similarity 比較兩個字串相似度OracleMILA字串
- 比較檔案是否相同,(比較MD5值)
- [C++] 自定義C++比較器比較大小C++
- Go和Python比較的話,哪個比較好?GoPython
- vector::shrink_to_fit()
- CSS flex-shrinkCSSFlex
- 列舉比較
- 常用 NoSQL 比較SQL
- Jsonunit 比較jsondiffJSON
- Integer的比較
- easyExcel & poi 比較Excel
- 主流CRM比較
- ==與equals比較
- Java 比較器Java
- CORS/JSONP比較CORSJSON