PK Nounique CASCADE DROP INDEX keep index

news2024/11/25 4:42:15
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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【网络基础实战之路】基于BGP协议连接三个AS区域的实战详解

系列文章传送门&#xff1a; 【网络基础实战之路】设计网络划分的实战详解 【网络基础实战之路】一文弄懂TCP的三次握手与四次断开 【网络基础实战之路】基于MGRE多点协议的实战详解 【网络基础实战之路】基于OSPF协议建立两个MGRE网络的实验详解 【网络基础实战之路】基于…

网页版的微信客户管理系统是怎样的?

登录账号密码&#xff1a; 微信扫码登录到系统上&#xff1a; 支持多个微信号登录到系统&#xff0c;聚合管理聊天&#xff0c;可以快速查看客服号的聊天记录 群发助手&#xff1a;群发可突破200 朋友圈功能&#xff1a;定时发圈&#xff0c;支持多个微信账号同步发圈、跟圈和一…

恒运资本:投资前瞻:储能产业迎政策密集支持 AIGC有望进入加速状态

昨日&#xff0c;沪指、深成指盘中弱势下探&#xff0c;创业板指冲高回落。到收盘&#xff0c;沪指跌0.49%报3244.49点&#xff0c;深成指跌0.53%报11039.45点&#xff0c;创业板指微跌0.01%报2228.73点&#xff0c;科创50指数跌0.85%&#xff1b;两市合计成交7366亿元&#xf…

STM32 F103C8T6学习笔记4:时钟树、滴答计时器、定时器定时中断

今日理解一下STM32F103 C8T6的时钟与时钟系统、滴答计时器、定时器计时中断的配置&#xff0c;文章提供原理&#xff0c;代码&#xff0c;测试工程下载。 目录 时钟树与时钟系统&#xff1a; 滴答计时器&#xff1a; 定时器计时中断&#xff1a; 测试结果&#xff1a; 测…

echarts3d柱状图

//画立方体三个面 const CubeLeft echarts.graphic.extendShape({shape: {x: 0,y: 0,width: 9.5, //柱状图宽zWidth: 4, //阴影折角宽zHeight: 3, //阴影折角高},buildPath: function (ctx, shape) {const api shape.api;const xAxisPoint api.coord([shape.xValue, 0]);con…

OSCS 闭门研讨第一期实录:软件供应链安全建设价值

2023 年 7 月 18 日晚 19:30&#xff0c;软件供应链安全技术交流群&#xff08;OSCS&#xff09;组织了第一次线上的闭门研讨会&#xff0c;本次研讨会我们收到 71 个来自各个企业关注软件供应链安全的技术专家的报名&#xff0c;根据研讨会参与规则要求&#xff0c;我们对报名…

一文告诉你,Intellij IDEA神器隐藏的11种实用小技巧!

el/2022/10/4 6:58:50 点击上方“程序员大咖”&#xff0c;选择“置顶公众号” 关键时刻&#xff0c;第一时间送达&#xff01; Intellij IDEA真是越用越觉得它强大&#xff0c;它总是在我们写代码的时候&#xff0c;不时给我们来个小惊喜。出于对Intellij IDEA的喜爱&#x…

【uniapp】uniapp打包H5(网页端):

文章目录 一、设置appid&#xff1a;二、设置router&#xff1a;三、打包&#xff1a;【1】[CLI 发行uni-app到H5&#xff1a;https://hx.dcloud.net.cn/cli/publish-h5](https://hx.dcloud.net.cn/cli/publish-h5)【2】HBuilderX 四、最终效果&#xff1a; 一、设置appid&…

W5100S-EVB-PICO 做TCP Server进行回环测试(六)

前言 上一章我们用W5100S-EVB-PICO开发板做TCP 客户端连接服务器进行数据回环测试&#xff0c;那么本章将用开发板做TCP服务器来进行数据回环测试。 TCP是什么&#xff1f;什么是TCP Server&#xff1f;能干什么&#xff1f; TCP (Transmission Control Protocol) 是一种面向连…

芯片常见测试手段:CP测试和FT测试

参考链接&#xff1a; 芯片测试的术语解释&#xff08;FT、CP&#xff09;&#xff0c;持续更新...._ft测试_染不尽的流年的博客-CSDN博客 如何区分芯片cp测试和ft测试 (baidu.com) 芯片常见测试手段&#xff1a;CP测试和FT测试 - 测量仪表 - 电子发烧友网 芯片测试是极其重要…

2023年加湿器市场数据分析(天猫数据分析怎么做)

随着人们生活水平提高、空调广泛使用&#xff0c;导致皮肤紧绷、口舌干燥、咳嗽感冒等空调病的滋生。可以看出&#xff0c;空气湿度与人体健康以及日常生活有着密切的联系。而加湿器作为室内空气湿度控制的重要工具&#xff0c;在近年来受到了越来越多的重视。根据鲸参谋电商数…

pytest 常用命令参数

-x 用例一旦失败或错误时就立即停止执行 共两条用例&#xff0c;运行第一条报错失败或报错&#xff0c;第二条就不会执行 pytest -vs -x test_pytest_study.py::TestCommon1 共2条用例&#xff0c;当执行到第一条失败时候&#xff0c;第二条不执行 --maxfailnum …

快速入门:【c# 之 Winform开发】

C#基础 面向对象(OOP) c语言是面向过程。 c是面向过程面向对象。 c#是纯粹的面向对象: 核心思想是以人的思维习惯来分析和解决问题。万物皆对象。 面向对象开发步骤: 分析对象 特征行为关系(对象关系/类关系) 写代码: 特征–>成员变量 方法–>成员方法 实例化–具体对…

26.配电网规划——考虑潮流约束的配电网规划

MATLAB代码直达&#xff1a;26.多时段-考虑潮流约束的配电网规划 clc;clear;close all; %% 导入数据 load(data.mat); MGpowerxlsread(MG1-3.xlsx); % 微电网的日负荷曲线 nt3 ; % 变压所个数 Sn25; % 变电所容量 MVA G…

第二、三章 线性表、栈、队列和数组

一、数据结构定义 线性表 顺序存储&#xff08;顺序表就是将线性表中的元素按照某种逻辑顺序&#xff0c;依次存储到从指定位置开始的一块连续的存储空间&#xff0c;重点是连续的存储空间。与数组非常接近&#xff09; 静态分配&#xff08;数组的大小和空间固定&#xff0c…

【IDEA问题】下载不了源代码

引出问题 最近不知道怎么打开 IDEA&#xff0c;本想查看源代码&#xff0c;然后点击下载源码&#xff0c;总是报找不到此对象的源代码。百度找了半天&#xff0c;GPT问了半天还是解决不了&#xff0c;直到遇到了这篇&#xff1a;idea中无法下载源码问题解决&#xff0c;终于得…

wms仓储管理系统是什么,wms仓储管理系统有什么用

阅读本文&#xff0c;您可以了解&#xff1a;1、wms仓储管理系统是什么&#xff1b;2、wms仓储管理系统有什么用 一、wms仓储管理系统是什么 WMS是Warehouse Management System&#xff08;仓储管理系统&#xff09;的缩写。它是一种用于优化和管理仓库操作的软件系统。WMS帮…

液压机行业分析报告:市场规模调查及行业发展趋势

液压机是一种以液体为工作介质&#xff0c;根据帕斯卡原理制成的用于传递能量以实现各种工艺的机器。液压机一般由本机&#xff08;主机&#xff09;、动力系统及液压控制系统三部分组成。 液压机应用领域 【汽车】液压机被汽车和卡车零件制造商用于原始设备和售后市场产品。…

小白到运维工程师自学之路 第七十二集 (半自动yum安装k8s集群)

一、准备环境 修改主机名 hostnamectl set-hostname k8s-master hostnamectl set-hostname k8s-node1 hostnamectl set-hostname k8s-node2 bashvim /etc/hosts 192.168.77.14 k8s-master 192.168.77.15 k8s-node1 192.168.77.16 k8s-node2 下载阿里源 wget -O /etc/yum…

Typora缩小行间距

Typora确实是个好工具&#xff0c;但行间距太宽&#xff0c;写东西写起来太难受&#xff0c;作为已经深度使用两天的大神(小白)终于找到了正确的打开方式&#xff0c;以下&#xff1a; Ⅰ.ShiftEnter # 不太推荐&#xff0c;不符合日常习惯&#xff0c;效果约等于单回车 Ⅱ.直…