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.rhkb.cn/news/85893.html

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

相关文章

自动切换HTTP爬虫ip助力Python数据采集

在Python的爬虫世界里&#xff0c;你是否也被网站的IP封锁问题困扰过&#xff1f;别担心&#xff0c;我来教你一个终极方案&#xff0c;让你的爬虫自动切换爬虫ip&#xff0c;轻松应对各种封锁和限制&#xff01;快来跟我学&#xff0c;让你的Python爬虫如虎添翼&#xff01; 首…

SpringBoot 项目使用 Redis 对用户 IP 进行接口限流

一、思路 使用接口限流的主要目的在于提高系统的稳定性&#xff0c;防止接口被恶意打击&#xff08;短时间内大量请求&#xff09;。 比如要求某接口在1分钟内请求次数不超过1000次&#xff0c;那么应该如何设计代码呢&#xff1f; 下面讲两种思路&#xff0c;如果想看代码可…

【redis 3.2 集群】

目录 一、Redis主从复制 1.概念 2.作用 2.1 数据冗余 2.2 故障恢复 2.3 负载均衡 2.4 高可用 3.缺点 4.流程 4.1 第一步 4.2 第二步 4.3 第三步 4.4 第四步 5.搭建 5.1 主 5.2 从 6.验证 二、Reids哨兵模式 1.概念 2.作用 2.1 监控 2.2 自动故障转移 2.…

ArcGIS Pro基础:【按顺序编号】工具实现属性字段的编号自动赋值

本次介绍一个字段的自动排序编号赋值工具&#xff0c;基于arcgis 的字段计算器工具也可以实现类似功能&#xff0c;但是需要自己写一段代码实现&#xff0c; 相对而言不是很方便。 如下所示&#xff0c;该工具就是【编辑】下的【属性】下的【按顺序编号】工具。 其操作方法是…

redis基础

目录 前言 一、概述 1.NoSQL 2.Redis 二、安装 1.编译安装 2.RPM安装 三、目录结构 四、命令解析 五、redis登录更改 六、数据库操作 &#xff08;一&#xff09;、登录数据库 1.本地 2.远程登录 &#xff08;二&#xff09;、数据操作 1.数据库操作 2.数据操作 …

C++笔记之将定时器加入向量并设置定时器的ID为i

C笔记之将定时器加入向量并设置定时器的ID为i code review! 文章目录 C笔记之将定时器加入向量并设置定时器的ID为i关于代码中的void operator()() 运行 代码 #include <chrono> #include <iostream> #include <thread> #include <vector>// 定义定时…

京东秋招攻略,备考在线测评和网申笔试

京东秋招简介 伴随着社会竞争越来越激烈&#xff0c;人们投递简历的岗位也变得越来越多元&#xff0c;而无论人们的选择面变成何样&#xff0c;那些知名度较高的企业&#xff0c;永远都备受关注&#xff0c;只要其一发布招聘公告&#xff0c;总有人第一时间踊跃报名。而作为这…

linux自启动程序

嵌入式linux下有软件需要自启动&#xff0c;只需要在/etc/init.d/rcS末尾添加所要启动的程序即可&#xff0c;开机就会自动运行 vi /etc/init.d/rcS在文件末尾添加 例&#xff1a;

Zabbix6 对接飞书告警

文章目录 Zabbix对接飞书告警背景创建飞书群组Zabbix配置创建告警媒介类型创建动作用户关联飞书告警 Zabbix对接飞书告警 背景 运维 你看下他的进程是不是挂了&#xff0c;之前在9点28分有发消息的&#xff0c;这次没有发消息 哐哐哐的去看了一通&#xff0c;确实有个进程之前…

Nginx的优化和防盗链

一、Nginx的优化 1、隐藏版本号 curl -I http://192.168.79.28 #查看信息&#xff08;版本号等&#xff09;方法一&#xff1a;修改配置文件 vim /usr/local/nginx/conf/nginx.conf vim /usr/local/nginx/conf/nginx.conf http {include mime.types;default_type ap…

【Grafana】中文界面配置 v10.0.3

比如通过 docker run -d -p 3000:3000 -v /e/code/monitor/grafana/grafana.ini.txt:/etc/grafana/grafana.ini grafana/grafana运行一个容器&#xff08;最新是v10.0.3&#xff09;。 在 /admin/settings 可以看到 users 部分有一个 default_language 配置。 所以在挂载到 …

在vue项目使用数据可视化 echarts ,柱状图、折线图、饼状图使用示例详解及属性详解

官网地址&#xff1a;Apache ECharts ​一、下载插件并在页面中引入 npm install echarts --save 页面导入&#xff1a; import * as echarts from echarts 全局导入&#xff1a; main.js 中&#xff0c;导入并注册到全局 import echarts from echarts Vue.prototype.$echart…

【算法】双指针——leetcode盛最多水的容器、剑指Offer57和为s的两个数字

盛水最多的容器 &#xff08;1&#xff09;暴力解法 算法思路&#xff1a;我们枚举出所有的容器大小&#xff0c;取最大值即可。 容器容积的计算方式&#xff1a; 设两指针 i , j &#xff0c;分别指向水槽板的最左端以及最右端&#xff0c;此时容器的宽度为 j - i 。由于容器…

2、简单上手+el挂载点+v-xx(v-text、v-html、v-on、v-show、v-if、v-bind、v-for)

官网&#xff1a; vue3&#xff1a;https://cn.vuejs.org/ vue2&#xff1a;https://v2.cn.vuejs.org/v2/guide/ 简单上手&#xff1a; 流程&#xff1a; 导入开发版本的Vue.js <!--开发环境版本&#xff0c;包含了有帮助的命令行警告--> <script src"https…

SD-MTSP:光谱优化算法LSO求解单仓库多旅行商问题MATLAB(可更改数据集,旅行商的数量和起点)

一、光谱优化算法LSO 光谱优化算法&#xff08;Light Spectrum Optimizer&#xff0c;LSO&#xff09;由Mohamed Abdel-Basset等人于2022年提出。 参考文献&#xff1a; [1]Abdel-Basset M, Mohamed R, Sallam KM, Chakrabortty RK. Light Spectrum Optimizer: A Novel Physi…

React Native 样式布局基础知识

通过此篇笔记能够学习到如下的几个知识点 在 React Native 中使用样式的一些细节了解 React Native 的 Flex 布局概念了解 React Native 的 flex 布局属性React Native 如何添加多样式属性React Native 中绝对布局和相对布局 React Native 中的 Flex 布局概念 1、主轴和交叉…

JVM运行时五大数据区域详解

前言&#xff1a; java虚拟机再执行Java程序的时候把它所拥有的内存区域划分了若干个数据区域。这些区域有着不同的功能&#xff0c;各司其职。这些区域不但功能不同&#xff0c;创建、销毁时间也不同。有些区域为线程私有&#xff0c;如&#xff1a;每个线程都有自己的程序计数…

《Zookeeper》源码分析(七)之 NIOServerCnxn的工作原理

目录 NIOServerCnxnreadPayload()handleWrite(k)process() NIOServerCnxn 在上一节IOWorkRequest的doWork()方法中提到会将IO就绪的key通过handleIO()方法提交给NIOServerCnxn处理&#xff0c;一个NIOServerCnxn代表客户端与服务端的一个连接&#xff0c;它用于处理两者之间的…

BGP实验

题目 IP地址配置 172.16.X.0/24为模拟用户环回接口接口 172.16.7.X/32为BGP邻居关系建立的环回接口 R1&#xff1a; R2&#xff1a; R3&#xff1a; R4&#xff1a; R5&#xff1a; R6&#xff1a; R7&#xff1a; R8&#xff1a; BGP邻居关系建立、宣告和反射器、联邦配置 R…

Web压测工具http_load原理分析

01、前言 http_load是一款测试web服务器性能的开源工具&#xff0c;从下面的网址可以下载到最新版本的http_load&#xff1a; http://www.acme.com/software/http_load/ 这个软件一直在保持着更新&#xff08;不像webbench&#xff0c;已经是十年的老古董了。 webbench的源…