資料遷移9 索引重建

2021-08-31 03:51:32 字數 817 閱讀 8051

1.什麼情況下索引會失效

當使用類似 alter table ****** truncate partition ***x_1 命令後,索引就會失效。

在對分割槽做ddl操作時,會使分割槽全域性索引失效,需要加上關鍵字update global indexes。

2.索引失效怎麼辦

重建索引。

3.重建索引的方法

a.首先查詢失效索引

select user_indexes where status=『unusable』 (注意不是小寫unusable)

b.重建索引的sql

alter index *** rebuild index (online);

4.避免方法

alter table ****** truncate partition ***x_1 update indexes

5.rebuild和rebuild online的區別

a、當rebuild 時一般對原先索引進行index fast full scan。

b、當rebuild online的時不用原先索引而執行table access full

c、rebuild和rebuild online都會發生sort,即需要用到temp表空間。

d、rebuild 會阻塞dml語句而rebuild online則不會。

e、rebuild online時系統會產生乙個sys_journal_***的iot型別的系統臨時日誌表,所有rebuild online時索引的變化都記錄在這個表中,當新的索引建立完成後,把這個表的記錄維護到新的索引中去,然後drop掉舊的索引,rebuild online就完成了。

重建ORACLE資料庫索引

declare str varchar2 400 begin 重建oracle索引 for tmp idx in select tablespace name,owner,table name,index name from all indexes where owner hnacms and te...

DBCC DBREINDEX 重建索引

transact sql 參考 重建指定資料庫中表的乙個或多個索引。語法dbcc dbreindex database.owner.table name index name fillfactor with no infomsgs 引數 database.owner.table name 是要重建其...

Oracle重建索引

如果表更新比較頻繁,那麼在索引中刪除標示會越來越多,這時索引的查詢效率必然降低,所以我們應該定期重建索引來消除索引中這些刪除標記。一般不會選擇先刪除索引,然後再重新建立索引,而是rebuild索引。在rebuild期間,使用者還可以使用原來的索引,並且rebuild新的索引時也會利用原來的索引資訊,...