Oracle 之表分析


1.oracle 刪除大量數據后整理表(analyze table xxx compute statistics)

DELETE 后 TRUNCATE TABLE ;

然后重新分析一下

analyze table tablename compute statistics

查看表信息

select NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN from user_tables where table_name=table_name;

2.Oracle 表刪除大量數據后,即使表中只有幾行記錄,但用select count(*) from table 來查詢發覺都不會馬上出來,
原因是該表的空間大了,查詢起來很慢。解決的方法是把該表所占用的表空間縮小,或者說釋放表空間。

alter table XXXX move; 這樣處理后就釋放了表空間了。

但是釋放表空間后,表的行號rowid會發生變化,而基於rowid的索引則會變成無效。因此該操作后必須重建索引。否則會 提示“ORA-01502: 索引'SMP.ITEMLOG_MID_IDX'或這類索引的分區處於不可用狀態”。
而重建索引的方法當然可以先drop掉再create ,但是這樣太麻煩了,用下面方法,這樣最快了,不會改變原來的索引結構。

alter index XXX rebuild;

3. 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

2、刪除分析SQL:

analyze table tablename delete statistics 會刪除所有的statistics

!!!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 NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN from user_tables where table_name=table_name;

觀察一下NUM_ROWS,BLOCKS,AVG_SPACE,AVG_ROW_LEN幾列你就會明白,這就是變化。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM