PK Nounique CASCADE DROP INDEX keep index

这篇具有很好参考价值的文章主要介绍了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

文章来源地址https://www.toymoban.com/news/detail-641662.html

到了这里,关于PK Nounique CASCADE DROP INDEX keep index的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Elasticsearch Index Monitoring(索引监控)之Index Stats API详解

    index_current 当前正在执行索引操作的个数。 index_failed 失败的索引操作次数。 delete_total 执行删除索引操作的次数。 delete_time_in_millis 删除索引操作总耗时。 delete_current 当前正在执行删除索引操作的个数。 noop_update_total 空更新总次数(检测到空更新的次数)。 is_throttled 索引是

    2024年04月09日
    浏览(42)
  • 小程序报错:Page “pages/index/index“ has not been registered yet

    提示:这里简述项目相关背景: 例如:项目场景:通过复制粘贴小程序页面时,微信开发者工具展示页面没有显示。 提示:这里描述项目中遇到的问题: 例如:在VSCode中复制粘贴Page里面的内容,撤回后小程序的内容没有展示。: 提示:这里填写问题的分析: 例如:暂时看

    2024年02月12日
    浏览(42)
  • Elasticsearch exception [type=index_not_found_exception, reason=no such index [**]]

     1.代码运行出现找不到Index,先排除index是否存在。   2.springboot和ES映射,默认是把对象类型映射为index,class对象默认是大写开头,所以要看是都是因为大小写不匹配。如若因为大小写原因导致,可以通过@Document注解指定index  

    2024年02月14日
    浏览(44)
  • MySQL索引(Index)

    数据库中的索引(Index)是一种数据结构,用于提高数据库查询性能和加速数据检索过程。索引可以看作是数据库表中某个或多个列的数据结构,类似于书中的目录,可以帮助数据库管理系统更快地定位和访问数据。它们是数据库优化的重要工具,特别是在处理大量数据时。

    2024年02月12日
    浏览(41)
  • ElasticSearch之Index modules

    索引的参数,分为两类: 静态参数,仅支持在创建索引时指定,或者关闭索引后指定。 动态参数,允许在索引工作期间指定或者修改。 静态参数 index.number_of_shards 默认值为 1 。 本参数用于控制主分片的数量,仅支持在创建时指定,对于已关闭的索引,修改本参数不会生效。

    2024年02月03日
    浏览(44)
  • MySQL基础(六)-索引(index)详解

    目录 一、什么是索引? 二、索引的实现原理 三、在MySQL中,主键、unique字段上会自动添加索引。 四、索引的创建与删除 创建索引: 删除索引: 五、查看SQL语句是否使用了索引 六、索引的失效 失效的第一种情况:模糊匹配当中以“%”开头 失效的第二种情况:使用or 失效的

    2024年02月16日
    浏览(44)
  • Hudi的核心概念 —— 索引(Index)

    Hudi 通过索引机制提供高效的 upserts,具体是将给定的 hoodie key(record key(记录键) + partition path)与文件 id(文件组)建立唯一映射。这种映射关系,数据第一次写入文件后保持不变, 所以,一个 FileGroup 包含了一批 record 的所有版本记录。Index 用于区分消息是 INSERT 还是 UPDAT

    2024年02月14日
    浏览(37)
  • elasticsearch 如何查看index的内容

    查看内容 1、使用 Elasticsearch 的 API 来进行查询,例如: 查看index大小 查看内容 其中 {index_name} 是要查询的 index 名称。 同时打印多个 要同时打印多个索引的内容,您可以使用 Elasticsearch 的 Multi Search API。以下是一个示例的 curl 命令: 在上面的示例中,我们通过多个 { \\\"index\\\"

    2024年02月11日
    浏览(36)
  • elasticsearch index sorting ,索引排序

    es默认的搜索排序是_score,通过评分排序,但是对于大数据量,评分一致的情况下也还是会乱序,官方说可以使用_doc,但是这个索引插入顺序是按照分片存的,也就是为2 的顺序可能多个分片都存在。所以实测并不好用。博主在做大数据量的排序时候,使用 datatime字段排序 ,解

    2024年02月04日
    浏览(54)
  • ES-index索引配置

      index索引配置项使用。 index_options   Index 有4中配置,可以控制倒排索引的内容。   Text类型默认记录positions,其他默认docs。记录的内容越多,所占用的空间越大。   Index 有4中配置如下: docs   记录 doc id 。 freqs   记录 doc id 和 term frequencies 。 positions   记录

    2023年04月08日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包