ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Oracle alter index disable/unusable的区别

2020-09-24 20:04:41  阅读:194  来源: 互联网

标签:index 00 object unusable disable SQL Net id


近日,在处理DAO层oracle/mysql尽可能通用的问题,把DDL抽到了过程中,alter index disable的时候报了个错“ORA-02243: ALTER INDEX 或 ALTER MATERIALIZED VIEW 选项无效”,经查,原因是disable,enable针对函数索引。普通索引为unusable和rebuild。如下:

SQL> create table test as select * from all_objects;

SQL> create index ind_t_object_id on test(object_id) nologging;
SQL> exec dbms_stats.gather_table_stats(user,'test',cascade => true);
SQL> set autotrace traceonly
SQL> select * from test where object_id = 20;
执行计划
----------------------------------------------------------
Plan hash value: 255872589
-----------------------------------------------------------------------------------------------
| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                 |     1 |    96 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST            |     1 |    96 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IND_T_OBJECT_ID |     1 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("OBJECT_ID"=20)
统计信息
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          2  consistent gets
          0  physical reads
          0  redo size
        910  bytes sent via SQL*Net to client
        327  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed


SQL> alter index ind_t_object_id disable;
alter index ind_t_object_id disable
*
第 1 行出现错误:
ORA-02243: ALTER INDEX 或 ALTER MATERIALIZED VIEW 选项无效

SQL> alter index ind_t_object_id unusable;
索引已更改。

SQL> select * from test where object_id = 20;
执行计划
----------------------------------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    96 |   168   (1)| 00:00:03 |
|*  1 |  TABLE ACCESS FULL| TEST |     1 |    96 |   168   (1)| 00:00:03 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("OBJECT_ID"=20)
统计信息
----------------------------------------------------------
        237  recursive calls
          0  db block gets
        795  consistent gets
          0  physical reads
          0  redo size
        910  bytes sent via SQL*Net to client
        327  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          5  sorts (memory)
          0  sorts (disk)
          0  rows processed
          
SQL> drop index ind_t_object_id;
索引已删除。


SQL> create index ind_t_object_id on test(to_char(object_id)) nologging;
索引已创建。


SQL> select * from test where to_char(object_id) = '20';
执行计划
----------------------------------------------------------
Plan hash value: 255872589
-----------------------------------------------------------------------------------------------
| Id  | Operation                   | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |                 |   518 | 49728 |    24   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST            |   518 | 49728 |    24   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | IND_T_OBJECT_ID |   207 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access(TO_CHAR("OBJECT_ID")='20')
统计信息
----------------------------------------------------------
         24  recursive calls
          0  db block gets
          5  consistent gets
          1  physical reads
          0  redo size
        910  bytes sent via SQL*Net to client
        327  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed


SQL> alter index ind_t_object_id disable;
索引已更改。
SQL> select * from test where to_char(object_id) = '20';
select * from test where to_char(object_id) = '20'
*
第 1 行出现错误:
ORA-30554: 基于函数的索引xx.xxx禁用

官方文档:

DISABLE Clause:
DISABLE applies only to a function-based index. This clause lets you disable the use of a function-based index. You might want to do so, for example, while working on the body of the function. Afterward you can either rebuild the index or specify another ALTER INDEX statement with the ENABLE keyword.


UNUSABLE Clause:
   UNUSABLE Clause Specify UNUSABLE to mark the index or index partition(s) or index subpartition(s) UNUSABLE. An unusable index must be rebuilt, or dropped and re-created, before it can be used. While one partition is marked UNUSABLE, the other partitions of the index are still valid. You can execute statements that require the index if the statements do not access the unusable partition. You can also split or rename the unusable partition before rebuilding it.

标签:index,00,object,unusable,disable,SQL,Net,id
来源: https://www.cnblogs.com/zhjh256/p/13726214.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有