實驗: Oracle中表shrink與move後index的狀態

來源:互聯網
上載者:User

1 move時實驗

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。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.