SQL> create table my_objects_move tablespace ASSM as select * from all_objects where rownum < 20000;
Table created
SQL> create index i_my_objects_move on my_objects_move (object_id);
Index created
SQL> delete from my_objects_move where object_name like '%C%';
7546 rows deleted
SQL> delete from my_objects_move where object_name like '%U%';
2959 rows deleted
SQL> commit;
Commit complete
SQL> alter table my_objects_move move;
Table altered
SQL> select index_name, status
2 from user_indexes
3 where index_name = 'I_MY_OBJECTS_MOVE';
INDEX_NAME STATUS
------------------------------ --------
I_MY_OBJECTS_MOVE UNUSABLE
SQL> alter index I_MY_OBJECTS_MOVE rebuild;
Index altered
SQL> select index_name, status
2 from user_indexes
3 where index_name = 'I_MY_OBJECTS_MOVE';
INDEX_NAME STATUS
------------------------------ --------
I_MY_OBJECTS_MOVE VALID
2 shrink时实验
SQL> create table my_objects tablespace ASSM as select * from all_objects where rownum < 20000;
Table created
SQL> create index i_my_objects on my_objects (object_id);
Index created
SQL> delete from my_objects where object_name like '%C%';
7546 rows deleted
SQL> delete from my_objects where object_name like '%U%';
2959 rows deleted
SQL> commit;
Commit complete
SQL> alter table my_objects enable row movement;
Table altered
SQL> alter table my_objects shrink space;
Table altered
SQL> select index_name, status
2 from user_indexes
3 where index_name = 'I_MY_OBJECTS';
INDEX_NAME STATUS
------------------------------ --------
I_MY_OBJECTS VALID
3 结论
shrink在移动行数据时,也一起维护了index上相应行的数据rowid的信息,当然shrink过程中用来维护index的成本也会比较高。而表move后index的状态是UNUSABLE的,需要进行rebuild。
————————————————
原文链接:https://blog.csdn.net/huang_xw/article/details/7016415