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


PURPOSEIn Oracle 9i, the DBA has an explicit control over how indexes are affectedwhile creating, disabling, or dropping Primary Key (PK) and unique constraints.This bulletin explains the different behaviours of indexes associated withPrimary Key or UNIQUE constraints according to the new clauses used when you execute one of the following commands:CREATE TABLE ... PRIMARY KEY/UNIQUEALTER TABLE  ... DISABLE PRIMARY KEY/UNIQUEALTER TABLE  ... DROP PRIMARY KEY/UNIQUESCOPE & APPLICATIONIt 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 samestatement.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 twostatements.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 NUMBERCONSTRAINT 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                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere 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 NUMBERCONSTRAINT 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                      UNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere 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 NUMBERCONSTRAINT 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                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                                                     PSQL> 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                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                      EMP_ID_IX                      PB. Disabling PK/UNIQUE constraints: what happens to the associated index ---------------------------------------------------------------------In Case 1 where the index was created explicitely within the same statementas 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;orALTER 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_IXC. Dropping PK/UNIQUE constraints: what happens to the associated index ---------------------------------------------------------------------In Case 1, where the index was created explicitely within the same statementas 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.hqwc.cn/news/69394.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

selenium语法进阶+常用API

目录 浏览器操作 浏览器回退&#xff0c;前进 与刷新 浏览器窗口设置大小 浏览器设置宽高 浏览器窗口最大化 浏览器控制滚动条 信息打印 打印页面的标题和当前页面的URL 定位一组元素 鼠标和键盘事件 键盘 鼠标 下拉框操作 通过索引定位&#xff08;se…

NPM与外部服务的集成(下)

目录 1、撤消访问令牌 2、在CI/CD工作流中使用私有包 2.1 创建新的访问令牌 持续整合 持续部署 交互式工作流 CIDR白名单 2.2 将令牌设置为CI/CD服务器上的环境变量 2.3 创建并签入特定于项目的.npmrc文件 2.4 令牌安全 3、Docker和私有模块 3.1 背景&#xff1a;运…

PyQt5编写可视化程序GB/T 34986-2017 产品加速试验方法(B 5.5 湿度试验)

GB/T 34986-2017 产品加速试验方法&#xff08;B 5.5 湿度试验&#xff09; 阿伦纽斯模型-温度&#xff08;Arrhenius Mode) 温度公式 AF exp{(Ea/K)[(1/Tu)-(1-Tt)]} 举例 AF exp{[0.68/(8.61738510e-5)][[1/(27325)]-[1/(273105)]]} ≈271.9518 AF 为加速因子 RHs 施加应力…

机器学习笔记 - 基于PyTorch + 类似ResNet的单目标检测

一、获取并了解数据 我们将处理年龄相关性黄斑变性 (AMD) 患者的眼部图像。 数据集下载地址,从下面的地址中,找到iChallenge-AMD,然后下载。 Baidu Research Open-Access Dataset - DownloadDownload Baidu Research Open-Access Datasethttps://ai.baidu.com/bro…

【FPGA零基础学习之旅#10】按键消抖模块设计与验证(一段式状态机实现)

&#x1f389;欢迎来到FPGA专栏~按键消抖模块设计与验证 ☆* o(≧▽≦)o *☆嗨~我是小夏与酒&#x1f379; ✨博客主页&#xff1a;小夏与酒的博客 &#x1f388;该系列文章专栏&#xff1a;FPGA学习之旅 文章作者技术和水平有限&#xff0c;如果文中出现错误&#xff0c;希望大…

日志采集分析ELK

这里的 ELK其实对应三种不同组件 1.ElasticSearch&#xff1a;基于Java&#xff0c;一个开源的分布式搜索引擎。 2.LogStash&#xff1a;基于Java&#xff0c;开源的用于收集&#xff0c;分析和存储日志的工具。&#xff08;它和Beats有重叠的功能&#xff0c;Beats出现之后&a…

无人机跟随一维高度避障场景--逻辑分析

无人机跟随一维高度避障场景--逻辑分析 1. 源由2. 视频3. 问题3.1 思维发散3.2 问题收敛 4. 图示4.1 水平模式4.2 下坡模式4.3 上坡模式4.4 碰撞分析 5. 总结5.1 一维高度避障场景5.2 业界跟随产品5.3 APM集成跟随 6. 参考资料7. 补充资料 - 大疆智能跟随7.1 炸机7.2 成功 1. 源…

安卓:网络框架okhttp

目录 一、okhttp介绍 1. OkHttpClient类&#xff1a; 常用方法&#xff1a; 2. Request类&#xff1a; 常用方法&#xff1a; 3. Response类&#xff1a; 常用方法&#xff1a; 4. Call类&#xff1a; 常用方法&#xff1a; 5. Interceptor接口&#xff1a; 常用方法&…

如何在 .NET Core WebApi 中处理 MultipartFormDataContent 中的文件

问题描述# 上图示例展示了用户通过 IOS 客户端发送请求时&#xff0c;对应后端接口接收到的 Request 内容。从请求内容的整体结果&#xff0c;我们可以看出这是一个 multipart/form-data 的数据格式&#xff0c;由于这种数据是由多个 multipart section 组成&#xff0c;所以我…

Reis过期删除策略

介绍 在Redis中&#xff0c;我们可以为键值对设置有效期&#xff0c;现在面临一个问题&#xff0c;如果一个键值对过期了&#xff0c;那么我们应该怎么删除呢&#xff1f; 我们目前有三种方案&#xff1a; 定时删除&#xff1a;在设置键的过期时间的同时&#xff0c;为此键设…

山西电力市场日前价格预测【2023-08-17】

日前价格预测 预测明日&#xff08;2023-08-17&#xff09;山西电力市场全天平均日前电价为376.70元/MWh。其中&#xff0c;最高日前电价为431.75元/MWh&#xff0c;预计出现在19: 45。最低日前电价为339.25元/MWh&#xff0c;预计出现在13: 15。 价差方向预测 1&#xff1a; 实…

WSL2 Ubuntu子系统安装OpenCV

文章目录 前言一、&#xfeff;基本概念二、操作步骤1.下载源码2.安装依赖3.运行编译4.配置路径 前言 OpenCV用C语言编写&#xff0c;它的主要接口也是C语言&#xff0c;但是依然保留了大量的C语言接口。该库也有大量的Python, Java and MATLAB/OCTAVE (版本2.5)的接口。这些语…