Oracle表刪除大量數據(千萬)后查詢變慢問題
1. delete 后 TRUNCATE TABLE ;然后重新分析一下 (analyze table tablename compute statistics)。
2.
Oracle 表刪除大量數據后,即使表中只有幾行記錄,但用select count(*) from table 來查詢發覺都不會馬上出來,
原因是該表的空間大了,查詢起來很慢。解決的方法是把該表所占用的表空間縮小,或者說釋放表空間。
alter table XXXX move; 這樣處理后就釋放了表空間了。
alter table XXXX move; 這樣處理后就釋放了表空間了。
但是釋放表空間后,表的行號rowid會發生變化,而基于rowid的索引則會變成無效。因此該操作后必須重建索引。
否則會 提示“ORA-01502: 索引'SMP.ITEMLOG_MID_IDX'或這類索引的分區處于不可用狀態”
而重建索引的方法當然可以先drop掉再create ,但是這樣太麻煩了,
用alter index XXX rebuild 這樣最快了,不會改變原來的索引結構。
3@URL>
Oracle分析表簡介
http://www.2cto.com/database/201106/94162.html
Oracle分析表簡介
Oracle分析表是Oracle數據庫管理的重要部分,下面就為您詳細介紹Oracle分析表方面的知識,希望對您學習Oracle分析表方
面能有所幫助。
1、分析SQL:
analyze table tablename compute statistics
等同于 analyze table tablename compute statistics for table for all indexes for all columns
for table的統計信息存在于視圖:user_tables 、all_tables、dba_tables
for all indexes的統計信息存在于視圖: user_indexes 、all_indexes、dba_indexes
for all columns的統計信息存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns
刪除分析SQL:
analyze table tablename delete statistics 會刪除所有的statistics
2、Oracle分析表的作用:為了使基于CBO的執行計劃更加準確
DBA_tables的數據有變化,可做對比。詳見官方文檔:
Use the ANALYZE statement to collect non-optimizer statistics, for example, to:
Collect or delete statistics about an index or index partition, table or table partition, index-organized
table, cluster, or scalar object attribute.
Validate the structure of an index or index partition, table or table partition, index-organized table,
cluster, or object reference (REF)。
Identify migrated and chained rows of a table or cluster.
dbms_stats的作用主要是替代analyze的收集統計信息這一塊的功能,且在這一方面做了相當大程度上的增強。
以analyze table table_name compute statistics;這條為例,生成的統計信息會存在于user_tables這個視圖,查看一下
select * from user_tables where table_name=table_name;
觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會明白,這就是變化。
面能有所幫助。
1、分析SQL:
analyze table tablename compute statistics
等同于 analyze table tablename compute statistics for table for all indexes for all columns
for table的統計信息存在于視圖:user_tables 、all_tables、dba_tables
for all indexes的統計信息存在于視圖: user_indexes 、all_indexes、dba_indexes
for all columns的統計信息存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns
刪除分析SQL:
analyze table tablename delete statistics 會刪除所有的statistics
2、Oracle分析表的作用:為了使基于CBO的執行計劃更加準確
DBA_tables的數據有變化,可做對比。詳見官方文檔:
Use the ANALYZE statement to collect non-optimizer statistics, for example, to:
Collect or delete statistics about an index or index partition, table or table partition, index-organized
table, cluster, or scalar object attribute.
Validate the structure of an index or index partition, table or table partition, index-organized table,
cluster, or object reference (REF)。
Identify migrated and chained rows of a table or cluster.
dbms_stats的作用主要是替代analyze的收集統計信息這一塊的功能,且在這一方面做了相當大程度上的增強。
以analyze table table_name compute statistics;這條為例,生成的統計信息會存在于user_tables這個視圖,查看一下
select * from user_tables where table_name=table_name;
觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會明白,這就是變化。
posted on 2012-09-07 13:02 Dragon4s 閱讀(5255) 評論(0) 編輯 收藏 所屬分類: Oracle