PK Nounique CASCADE DROP INDEX keep index

Explicit Control Over Indexes when Creating, Disabling, or Dropping PK/Unique Constraints (Doc ID 139666.1)​编辑To Bottom



 

PURPOSE
  In Oracle 9i, the DBA has an explicit control over how indexes are affected
  while creating, disabling, or dropping Primary Key (PK) and unique 
  constraints.

  This bulletin explains the different behaviours of indexes associated with
  Primary Key or UNIQUE constraints according to the new clauses used when you 
  execute one of the following commands:
  
     CREATE TABLE ... PRIMARY KEY/UNIQUE
     ALTER TABLE  ... DISABLE PRIMARY KEY/UNIQUE
     ALTER TABLE  ... DROP PRIMARY KEY/UNIQUE


SCOPE & APPLICATION
  It is important for DBAs to know what happens to the indexes when creating,
  disabling or dropping a constraint relying on an index, since indexes may 
  have to be rebuilt after these operations. This can have two consequences:
 
    - Indexes may be missing for the Cost Based Optimizer (CBO) if the DBA 
      thinks that the index was not dropped. This can have a major impact on 
      performance.
    - Index rebuilding takes time.


Explicit control over INDEXES when DISABLING/DROPPING PK, Unique constraints:
=============================================================================

A. Creation of Primary Key/Unique constraints and associated index 
   ----------------------------------------------------------------

   In the following views, depending on the way you created the Primary Key (PK)
   or UNIQUE constraint and its associated index, you get these different 
   combinations:

                                       +-----------------+        +------------+
                                       | DBA_CONSTRAINTS |        | DBA_INDEXES|
                                       +-----------------+        +------------+
                                   -----------------------------   ------------
                                   Constraint_name   Index_name     Index_name
                                   --------------- -------------   ------------
Case 1: Create constraint, and index   PK_EMP_ID     EMP_ID_IX      EMP_ID_IX    
        explicitely within the same
        statement.


Case 2: Create constraint, and index   PK_EMP_ID     PK_EMP_ID      PK_EMP_ID    
        implicitely within the same 
        statement.


Case 3: Create constraint and index    PK_EMP_ID         -          EMP_ID_IX   
        separately within two
        statements.
        Enable the constraint.         PK_EMP_ID     EMP_ID_IX      EMP_ID_IX


-------------------------------------------------------------------------
Case 1: Create constraint and index explicitely within the same statement
-------------------------------------------------------------------------

SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.

SQL> create table <OWNER>.<TABLE_NAME>
     (emp_id NUMBER
             CONSTRAINT pk_emp_id PRIMARY KEY USING INDEX
             (CREATE INDEX <OWNER>.emp_id_ix ON <OWNER>.<TABLE_NAME>(emp_id)
              TABLESPACE indx),
      ename VARCHAR2(12),
      sal   number);

Table created.


SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';

    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    EMP_ID_IX                      NONUNIQUE

SQL> select constraint_name,index_name, constraint_type from dba_constraints
     where table_name='<TABLE_NAME>' and constraint_type='P';

    CONSTRAINT_NAME                INDEX_NAME                     C
    ------------------------------ ------------------------------ -
    PK_EMP_ID                      EMP_ID_IX                      P


-------------------------------------------------------------------------
Case 2: Create constraint and index implicitely within the same statement
-------------------------------------------------------------------------

SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.

SQL> create table <OWNER>.<TABLE_NAME>
     (emp_id NUMBER
             CONSTRAINT pk_emp_id PRIMARY KEY USING INDEX TABLESPACE indx,
      ename VARCHAR2(12),
      sal   number);

Table created.


SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';

    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    PK_EMP_ID                      UNIQUE

SQL> select constraint_name,index_name, constraint_type from dba_constraints
     where table_name='<TABLE_NAME>' and constraint_type='P';

    CONSTRAINT_NAME                INDEX_NAME                     C
    ------------------------------ ------------------------------ -
    PK_EMP_ID                      PK_EMP_ID                      P
 

--------------------------------------------------------------------
Case 3: Create constraint and index separately within two statements
--------------------------------------------------------------------

SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.

SQL> create table <OWNER>.<TABLE_NAME>
     (emp_id NUMBER
             CONSTRAINT pk_emp_id PRIMARY KEY  DISABLE,
      ename VARCHAR2(12),
      sal   number);

Table created.


SQL> create index <OWNER>.emp_id_ix on <OWNER>.<TABLE_NAME>(emp_id)
     tablespace indx;
Index created.

SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';

    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    EMP_ID_IX                      NONUNIQUE

SQL> select constraint_name,index_name, constraint_type from dba_constraints
     where table_name='<TABLE_NAME>' and constraint_type='P';

    CONSTRAINT_NAME                INDEX_NAME                     C
    ------------------------------ ------------------------------ -
    PK_EMP_ID                                                     P

SQL> alter table <OWNER>.<TABLE_NAME> ENABLE constraint pk_emp_id;
Table altered.

SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';

    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    EMP_ID_IX                      NONUNIQUE

SQL> select constraint_name,index_name, constraint_type from dba_constraints
     where table_name='<TABLE_NAME>' and constraint_type='P';

    CONSTRAINT_NAME                INDEX_NAME                     C
    ------------------------------ ------------------------------ -
    PK_EMP_ID                      EMP_ID_IX                      P



B. Disabling PK/UNIQUE constraints: what happens to the associated index 
   ---------------------------------------------------------------------

   In Case 1 where the index was created explicitely within the same statement
   as the constraint, the index is in both cases disassociated from the 
   constraint; depending on the clause "CASCADE DROP INDEX" usage, the index is 
   dropped or not.

   In traditionnal Case 2, the behavior remains the same: using the clause 
   "CASCADE DROP INDEX" or not does not influence the usual behavior: it 
   automatically drops the relying index.
  
   In case 3, disabling the constraint drops the index or not: 
       * if the constraint has never been enabled, it never drops the index.
       * but in most cases, the constraint has been enabled for some time. 
         In this case, the clause "CASCADE DROP INDEX" drops the index.
                   
   
                                       +-----------------+       +------------+
                                       | DBA_CONSTRAINTS |       | DBA_INDEXES|
                                       +-----------------+       +------------+
                                  -----------------------------   ------------
                                  Constraint_name   Index_name     Index_name
                                  --------------- -------------   ------------
Case 1: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -        
                CASCADE DROP INDEX;
        or
        ALTER TABLE ... DISABLE PK;    PK_EMP_ID         -         EMP_ID_IX    
                                                                 
 
Case 2: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -       
                CASCADE DROP INDEX;
        or 
        ALTER TABLE ... DISABLE PK;    PK_EMP_ID         -             -      


Case 3: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -    
                CASCADE DROP INDEX;
        or 
        ALTER TABLE ... DISABLE PK;    PK_EMP_ID         -         EMP_ID_IX



C. Dropping PK/UNIQUE constraints: what happens to the associated index 
   ---------------------------------------------------------------------

   In Case 1, where the index was created explicitely within the same statement
   as the constraint, the index is by default KEPT when the constraint is 
   dropped.
   If you want the index to be dropped, you have to explicitely ask for it 
   through the "DROP INDEX" clause.

   In case 2, the behavior is the opposite: if you want the index to be kept 
   and the constraint dropped, you have to explicitly ask for it with the 
   "KEEP INDEX" clause; otherwise the index is DROPPED by default.

   In Case 3, dropping the constraint drops the index or not: 
       * if the constraint has never been enabled, it never drops the index.
       * but in most cases, the constraint has been enabled for some time. 
         Then the index is by default KEPT when the constraint is dropped. If 
         you want the index to be dropped, you have to explicitly ask for it 
         with the "DROP INDEX" clause.


                                             +-----------------+   +-----------+
                                             | DBA_CONSTRAINTS |   |DBA_INDEXES|
                                             +-----------------+   +-----------+
                                           ----------------------- ------------
                                           Constraint  Index_name   Index_name
                                           ----------- ----------- ------------
Case 1: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -       
Case 1: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       EMP_ID_IX              
Case 1: ALTER TABLE ... DROP PK;                -            -       EMP_ID_IX   
                                                              

Case 2: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -                                                      
Case 2: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       PK_EMP_ID                                                              
Case 2: ALTER TABLE ... DROP PK;                -            -           -       


Case 3: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -   
Case 3: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       EMP_ID_IX   
Case 3: ALTER TABLE ... DROP PK;                -            -       EMP_ID_IX

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/79370.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

分类预测 | MATLAB实现GWO-BiGRU-Attention多输入分类预测

分类预测 | MATLAB实现GWO-BiGRU-Attention多输入分类预测 目录 分类预测 | MATLAB实现GWO-BiGRU-Attention多输入分类预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.GWO-BiGRU-Attention 数据分类预测程序 2.代码说明&#xff1a;基于灰狼优化算法&#xff08;GW…

Redis——hash类型详解

概述 Redis本身就是键值对结构&#xff0c;而Redis中的value可以是哈希类型&#xff0c;为了区分这两个键值对&#xff0c;Redis中的键值对是key-value&#xff0c;而value中的哈希键值对则是field-value&#xff0c;其中value必须是字符串 下面介绍一些Redis的hash类型的常用…

归并排序 与 计数排序

目录 1.归并排序 1.1 递归实现归并排序&#xff1a; 1.2 非递归实现归并排序 1.3 归并排序的特性总结: 1.4 外部排序 2.计数排序 2.1 操作步骤: 2.2 计数排序的特性总结: 3. 7种常见比较排序比较 1.归并排序 基本思想: 归并排序(MERGE-SORT)是建立在归并操作上的一种…

集简云本周新增/更新:新增3大功能,集成19款应用,更新5款应用,新增近290个动作

本周更新概要 功能更新 ◉ 新增功能&#xff1a;语聚AI开放API功能 ◉ 新增功能&#xff1a;数据表表格公开分享功能 ◉ 新增功能&#xff1a;浏览器页面操作页面内容读取(增强版本&#xff09; 应用新增 新增应用&#xff1a;赛捷CRM 新增应用&#xff1a;快跑者 新增应…

Matplotlib数据可视化(六)

目录 1.绘制概率图 2.绘制雷达图 3.绘制流向图 4.绘制极坐标图 5.绘制词云图 1.绘制概率图 from scipy.stats import norm fig,ax plt.subplots() plt.rcParams[font.family] [SimHei] np.random.seed() mu 100 sigma 15 x musigma*np.random.randn(437) num_bins …

GRPC 学习记录

GRPC 安装 安装 grpcio、grpcio-tools、protobuf、 pip install grpcio -i https://pypi.tuna.tsinghua.edu.cn/simple pip install grpcio-tools -i https://pypi.tuna.tsinghua.edu.cn/simple pip install protobuf -i https://pypi.tuna.tsinghua.edu.cn/simple常用类型 p…

ai之美:探索写真照片软件的创造力

小青&#xff1a;嘿&#xff0c;小华&#xff0c;你知道最近ai艺术写真非常流行吗&#xff1f; 小华&#xff1a;真的吗&#xff1f;我还不知道呢。告诉我更多细节吧&#xff01; 小青&#xff1a;好的&#xff0c;ai艺术写真是指使用人工智能技术将照片转化为艺术作品的过程…

arcgis数据采集与拓扑检查

1、已准备好一张配准好的浙江省行政区划图&#xff0c;如下&#xff1a; 2、现在需要绘制湖州市县级行政区划。需要右击文件夹新建文件地理数据库&#xff0c;如下&#xff1a; 其余步骤均默认即可。 创建好县级要素数据集后&#xff0c;再新建要素类&#xff0c;命名为县。 为…

Unity制作一个简单的登入注册页面

1.创建Canvas组件 首先我们创建一个Canvas画布&#xff0c;我们再在Canvas画布底下创建一个空物体&#xff0c;取名为Resgister。把空物体的锚点设置为全屏撑开。 2.我们在Resgister空物体底下创建一个Image组件&#xff0c;改名为bg。我们也把它 的锚点设置为全屏撑开状态。接…

【python实现向日葵控制软件功能】手机远程控制电脑

大家好&#xff0c;我是csdn的博主&#xff1a;lqj_本人 这是我的个人博客主页&#xff1a; lqj_本人_python人工智能视觉&#xff08;opencv&#xff09;从入门到实战,前端,微信小程序-CSDN博客 最新的uniapp毕业设计专栏也放在下方了&#xff1a; https://blog.csdn.net/lbcy…

【CUDA】学习记录(4)-线程束的执行

线程模型 block&#xff1a;同一个block内共享内存&#xff0c;同一block中的thread可以彼此进行通信。 block&#xff1a;block-local synchronization。同一个块内的线程可以同步。 线程&#xff0c;可以根据blockIdx和threadIdx唯一的指定。 作者&#xff1a;不会code的程序…

MongoDB:数据库初步应用

一.连接MongoDB 1.MongoDBCompass连接数据库 连接路径:mongodb://用户名:密码localhost:27017/ 2.创建数据库(集合) MongoDB中数据库被称为集合. MongoDBCompass连接后,点击红色框加号创建集合,点击蓝色框加号创建文档(数据表) 文档中的数据结构(相当于表中的列)设计不用管…

Linux——KVM虚拟化

目录标题 虚拟化技术虚拟化技术发展案例KVM简介KVM架构及原理KVM原理KVM虚拟化架构/三种模式虚拟化前、虚拟化后对比KVM盖中盖套娃实验 虚拟化技术 通过虚拟化技术将一台计算机虚拟为多台逻辑计算机&#xff0c;在一台计算机上同时运行多个逻辑计算机&#xff0c;同时每个逻辑…

PHP自己的框架实现config配置层级存取(完善篇二)

1、实现效果 config(include_once $coreConfig); //加载配置文件config() //获取所有配置 config(DB_HOST) 获取配置 2、按层级配置文件加载&#xff0c;存取配置项 config,function.php function config($varNULL,$valueNULL){static $configarray();if(is_array($var)){…

驱动day5

思维导图 练习 实现设备文件和设备的绑定&#xff0c;编写LED驱动 head.h #ifndef __HEAD_H__ #define __HEAD_H__typedef struct {unsigned int MODER;unsigned int OTYPER;unsigned int OSPEEDR;unsigned int PUPDR;unsigned int IDR;unsigned int ORD; }gpio_t;#define G…

“RFID与光伏板的完美融合:探索能源科技的新时代!“

随着科技的不断发展&#xff0c;人类创造出了许多令人惊叹的发明。其中&#xff0c;RFID&#xff08;Radio Frequency Identification&#xff09;技术的应用在各个领域日益广泛。最近的研究表明&#xff0c;将RFID技术应用于光伏板领域&#xff0c;不仅可以提高光伏板的效率&a…

kafka集成篇

kafka的Java客户端 生产者 1.引入依赖 <dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-clients</artifactId><version>2.6.3</version></dependency>2.生产者发送消息的基本实现 /*** 消息的发送⽅*/ …

常见的Web安全漏洞有哪些,Web安全漏洞常用测试方法介绍

Web安全漏洞是指在Web应用程序中存在的可能被攻击者利用的漏洞&#xff0c;正确认识和了解这些漏洞对于Web应用程序的开发和测试至关重要。 一、常见的Web安全漏洞类型&#xff1a; 1、跨站脚本攻击(Cross-Site Scripting&#xff0c;XSS)&#xff1a;攻击者通过向Web页面注入…

Redis的单线程与多线程

Redis的核心处理逻辑一直都是单线程 有一些分支模块是多线程(某些异步流程从4.0开始用的多线程&#xff0c;例如UNLINK、FLUSHALL ASYNC、FLUSHDB ASYNC等非阻塞的删除操作。网络I/O解包从6.0开始用的是多线程;) 为什么是单线程 多线程多好啊可以利用多核优势 官方给的解释 …

罗勇军 →《算法竞赛·快冲300题》每日一题:“质因子数量” ← 快速幂、素数筛

【题目来源】http://oj.ecustacm.cn/problem.php?id1780http://oj.ecustacm.cn/viewnews.php?id1023【题目描述】 给出n个数字&#xff0c;你可以任意选择一些数字相乘&#xff0c;相乘之后得到新数字x。 其中&#xff0c;x的分数等于x不同质因子的数量。 请你计算所有选择数…