Oracle表table與索引index的分析及索引重建及統(tǒng)計信息導(dǎo)入導(dǎo)出

1.分析表與索引(analyze 不會重建索引)

10年積累的成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有廣漢免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

analyze table tablename compute statistics
等同于 analyze table tablename compute statistics for table for all indexes for all columns

for table 的統(tǒng)計信息存在于視圖:user_tables 、all_tables、dba_tables

for all indexes 的統(tǒng)計信息存在于視圖: user_indexes 、all_indexes、dba_indexes

for all columns 的統(tǒng)計信息存在于視圖:user_tab_columns、all_tab_columns、dba_tab_columns

注:分析表與索引見 Analyze All Table存儲過程

2、一般來講可以采用以下三種方式來手工分析索引。
analyze index idx_t validate structure:
analyze index idx_t compute statistics:
analyze index idx_t estimate statistics sample 10 percent

1)analyze index idx_t validate structure:
這段分析語句是用來分析索引的block中是否有壞塊兒,那么根據(jù)分析我們可以得到索引的結(jié)構(gòu)數(shù)據(jù),這些數(shù)據(jù)會保留到
index_stats中,來判斷這個索引是否需要rebuild. 需要注意的是這樣的分析是不會收集索引的統(tǒng)計信息的。

2)validate structure有二種模式: online, offline, 一般來講默認(rèn)的方式是offline。
當(dāng)以offline的模式analyze索引時,會對table加一個表級共享鎖,對目前table的一些實時DMl操作會產(chǎn)生一定的影響。
而以online模式分析時候,則不會加任何lock,但在index_stats中是看不到任何信息的。

3)analyze index idx_t compute statistics:
用來統(tǒng)計索引的統(tǒng)計信息(全分析),主要為CBO服務(wù)。

4)analyze index idx_t estimate statistics sample 10 percent
主要是用來指定比例進行抽樣分析,也是為CBO服務(wù). 例中是抽樣10%

3.重建索引

alter index index_name rebuild tablespace tablespace_name
alter index index_name rebuild tablespace tablespace_name 加入表空間名,會將指定的索引移動到指定的表空間當(dāng)中。

注:
analyze 操作只是統(tǒng)計信息,并將統(tǒng)計信息存放起來供日后分析SQL使用,不進行重建之類的具體實施性操作,因此要重建索引的話
還是要用 alter index index_name rebuild

4、其他的統(tǒng)計方法

1)DBMS_STATS:這個當(dāng)然是最強大的分析包了
--創(chuàng)建統(tǒng)計信息歷史保留表
exec dbms_stats.create_stat_table(ownname => 'scott',stattab => 'stat_table');

--導(dǎo)出整個scheme的統(tǒng)計信息
exec dbms_stats.export_schema_stats(ownname => 'scott',stattab => 'stat_table');

--分析scheme
Exec dbms_stats.gather_schema_stats(ownname => 'test',options => 'GATHER AUTO',estimate_percent => dbms_stats.auto_sample_size,method_opt => 'for all indexed columns', degree => 6 );

--分析表的統(tǒng)計信息
exec dbms_stats.gather_table_stats(ownname => 'TEST',tabname => 'sm_user',estimate_percent => 10,method_opt=> 'for all indexed columns') ;

--分析索引的統(tǒng)計信息
exec dbms_stats.gather_index_stats(ownname => 'TEST',indname => 'pk_user_index',estimate_percent => '10',degree => '4') ;

--如果發(fā)現(xiàn)執(zhí)行計劃走錯,刪除表的統(tǒng)計信息
exec dbms_stats.delete_table_stats(ownname => 'TEST',tabname => 'SM_USER') ;

--導(dǎo)入表的歷史統(tǒng)計信息
exec dbms_stats.import_table_stats(ownname => 'TEST',tabname => 'SM_USER',stattab => 'stat_table') ;

--如果進行分析后,大部分表的執(zhí)行計劃都走錯,需要導(dǎo)回整個scheme的統(tǒng)計信息
exec dbms_stats.import_schema_stats(ownname => 'TEST',stattab => 'SM_USER');

--導(dǎo)入索引的統(tǒng)計信息
exec dbms_stats.import_index_stats(ownname => 'TEST',indname => 'PK_USER_INDEX',stattab => 'stat_table')

analyze和dbms_stats不同的地方:
analyze是同時更新表和索引的統(tǒng)計信息,而dbms_stats會先更新表的統(tǒng)計信息,然后再更新索引的統(tǒng)計信息,
這里就有一個問題,就是當(dāng)表的統(tǒng)計信息更新后,而索引的統(tǒng)計信息沒有被更新,這時候cbo就有可能選擇錯誤的plan

2)DBMS_UTILITY.ANALYZE_SCHEMA:可直接分析SCHEMA中所有對象
   如:EXEC DBMS_UTILITY.ANALYZE_SCHEMA ('LTTFM','COMPUTE');

3)DBMS_DDL.ANALYZE_OBJECT:收集對象的的統(tǒng)計信息

新聞名稱:Oracle表table與索引index的分析及索引重建及統(tǒng)計信息導(dǎo)入導(dǎo)出
轉(zhuǎn)載來于:http://muchs.cn/article10/isjpgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、電子商務(wù)、網(wǎng)站導(dǎo)航、網(wǎng)站制作、網(wǎng)站排名、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)