|
做了个简单的测试,发现alter table move真的会对index有影响,这个以前倒是没有注意
SQL> create table test (id int);
SQL> create index ind_test on test(id);
SQL> insert into test values (1);
SQL> select * from test where id = 1;
Execution Plan
----------------------------------------------------------
Plan hash value: 2388774261
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IND_TEST | 1 | 13 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
SQL> alter table test move;
SQL> select * from test where id = 1;
Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 13 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
If you search the column status in the user_indexes, you will find that the status changed to UNUSABLE
select u_ind.index_name, u_ind.table_name, u_ind.status from user_indexes u_ind.
However after rebuild index online, you will find it is back online again
SQL> alter index IND_TEST rebuild online;
Index altered.
SQL> set autotrace traceonly exp
SQL> select * from test where id = 1;
Execution Plan
----------------------------------------------------------
Plan hash value: 2388774261
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IND_TEST | 1 | 13 | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------- |
|