Oracle索引(2)索引的修改与维护

修改索引

  利用alter index语句可以完成的操作

   重建或合并索引

  回收索引未使用的空间或为索引非配新空间

  修改索引是否可以并行操作及并行度

  修改索引的存储参数以及物理属性

  指定Logging或nologging 

  启用或禁用索引压缩

  标记索引不可用

  标记索引不可见

  启动或关闭对索引的监控

  1.修改索引参数设置

     修改索引emp_job_indx的存储参数与物理属性参数

SQL> alter index emp_job_index initrans 20 storage(next 50K);

索引已更改。

 2.合并索引与重建索引

   (1)合并索引:

      合并dept_dname_indx索引的存储碎片

SQL> alter index  dep_dname_unique coalesce;--COALESCE

索引已更改。

 (2)重建索引

   清楚碎片的还有一种方式就是重建索引,这样还可以重新设置参数等

重建dept_dname_index索引   

SQL> alter index dep_dname_unique rebuild;

索引已更改。

   合并索引:
                1.不能将索引移动到其他表空间
                2.代价比较低,不需要使用额外的存储空间
                3.只能在B树的同一子树种进行合并,不会改变树的高度
                4.可以快速释放叶子节点中未使用的存储空间
        重建索引:
                1.可以将索引移动到其他的表空间
                2.代价比较高,需要使用额外的存储空间
                3.重建整个B树,可以降低B树的高度
                4.可以快递更改索引存储参数,如果在重建中指出了ONLINE关键字,还可以再重建索引时使用索引。

   3.禁用和启用函数索引

   (1).禁用函数索引

   禁用 emp_fname_indx

SQL> alter index  emp_fname_indx disable;

索引已更改。

 (2).启用函数索引

SQL> alter index  emp_fname_indx enable;

索引已更改。

 4.手动分配与回收索引存储空间

(1).为索引手动分配存储空间

SQL> alter index  emp_fname_indx allocate extent (size 100K datefile  'D:disk3	bs3_1.dbf') ;

(2).回收存储空间

SQL> alter index  emp_fname_indx deallocate unused;

索引已更改。

  5.重名

SQL> alter index emp_fname_indx rename to emp_fname_index;

索引已更改。

  6.打开监控与关闭监控

(1)开打监控

     

SQL> alter index  emp_fname_index monitoring usage;

索引已更改。

  (2)关闭

SQL> alter index  emp_fname_index nomonitoring usage;

索引已更改。

  

维护索引

    1.删除索引

       一下的情况可以删除索引

        (1)索引不再使用

        (2)索引并没有提高检索性能。

        (3)通过监控,很少使用的索引

        (4)重建索引,因为有太多的碎片

        (5)由于移动了表数据等操作导致索引失效。     

SQL> drop index emp_fname_index;

索引已删除。

  

2.查询所有信息

     

原文地址:https://www.cnblogs.com/evencao/p/3181411.html