Oracle表刪除大量數(shù)據(jù)(千萬)后查詢變慢問題
1. delete 后 TRUNCATE TABLE ;然后重新分析一下 (analyze table tablename compute statistics)。
2.
Oracle 表刪除大量數(shù)據(jù)后,即使表中只有幾行記錄,但用select count(*) from table 來查詢發(fā)覺都不會(huì)馬上出來,
原因是該表的空間大了,查詢起來很慢。解決的方法是把該表所占用的表空間縮小,或者說釋放表空間。
alter table XXXX move; 這樣處理后就釋放了表空間了。
alter table XXXX move; 這樣處理后就釋放了表空間了。
但是釋放表空間后,表的行號(hào)rowid會(huì)發(fā)生變化,而基于rowid的索引則會(huì)變成無效。因此該操作后必須重建索引。
否則會(huì) 提示“ORA-01502: 索引'SMP.ITEMLOG_MID_IDX'或這類索引的分區(qū)處于不可用狀態(tài)”
而重建索引的方法當(dāng)然可以先drop掉再create ,但是這樣太麻煩了,
用alter index XXX rebuild 這樣最快了,不會(huì)改變?cè)瓉淼乃饕Y(jié)構(gòu)。
3@URL>
Oracle分析表簡(jiǎn)介
http://www.2cto.com/database/201106/94162.html
Oracle分析表簡(jiǎn)介
Oracle分析表是Oracle數(shù)據(jù)庫管理的重要部分,下面就為您詳細(xì)介紹Oracle分析表方面的知識(shí),希望對(duì)您學(xué)習(xí)Oracle分析表方
面能有所幫助。
1、分析SQL:
analyze table tablename compute statistics
等同于 analyze table tablename compute statistics for table for all indexes for all columns
for table的統(tǒng)計(jì)信息存在于視圖:user_tables 、all_tables、dba_tables
for all indexes的統(tǒng)計(jì)信息存在于視圖: user_indexes 、all_indexes、dba_indexes
for all columns的統(tǒng)計(jì)信息存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns
刪除分析SQL:
analyze table tablename delete statistics 會(huì)刪除所有的statistics
2、Oracle分析表的作用:為了使基于CBO的執(zhí)行計(jì)劃更加準(zhǔn)確
DBA_tables的數(shù)據(jù)有變化,可做對(duì)比。詳見官方文檔:
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的收集統(tǒng)計(jì)信息這一塊的功能,且在這一方面做了相當(dāng)大程度上的增強(qiáng)。
以analyze table table_name compute statistics;這條為例,生成的統(tǒng)計(jì)信息會(huì)存在于user_tables這個(gè)視圖,查看一下
select * from user_tables where table_name=table_name;
觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會(huì)明白,這就是變化。
面能有所幫助。
1、分析SQL:
analyze table tablename compute statistics
等同于 analyze table tablename compute statistics for table for all indexes for all columns
for table的統(tǒng)計(jì)信息存在于視圖:user_tables 、all_tables、dba_tables
for all indexes的統(tǒng)計(jì)信息存在于視圖: user_indexes 、all_indexes、dba_indexes
for all columns的統(tǒng)計(jì)信息存在于試圖:user_tab_columns、all_tab_columns、dba_tab_columns
刪除分析SQL:
analyze table tablename delete statistics 會(huì)刪除所有的statistics
2、Oracle分析表的作用:為了使基于CBO的執(zhí)行計(jì)劃更加準(zhǔn)確
DBA_tables的數(shù)據(jù)有變化,可做對(duì)比。詳見官方文檔:
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的收集統(tǒng)計(jì)信息這一塊的功能,且在這一方面做了相當(dāng)大程度上的增強(qiáng)。
以analyze table table_name compute statistics;這條為例,生成的統(tǒng)計(jì)信息會(huì)存在于user_tables這個(gè)視圖,查看一下
select * from user_tables where table_name=table_name;
觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會(huì)明白,這就是變化。
posted on 2012-09-07 13:02 Dragon4s 閱讀(5255) 評(píng)論(0) 編輯 收藏 所屬分類: Oracle