日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle 唯一约束作用,想问下在表上建唯一索引和使用索引+唯一约束,从功能和性能来说有什么差别?...

發(fā)布時間:2025/3/21 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle 唯一约束作用,想问下在表上建唯一索引和使用索引+唯一约束,从功能和性能来说有什么差别?... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

index+unique constraint 和 unique index 的區(qū)別好像執(zhí)行計劃不同~

SQL> drop table test;

Table dropped

SQL> create table test as select * from all_objects;

Table created

SQL> create index ind_TEST on test(object_id);

Index created

SQL> alter table test add constraint un_test unique(object_id) using index ind_test;

Table altered

SQL> insert into test select * from all_objects;

insert into test select * from all_objects

ORA-00001: 違反唯一約束條件 (SCOTT.UN_TEST)

SQL> explain plan for

2??select object_id from test where object_id=32;

Explained

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------

Plan hash value: 2388774261

-----------------------------------------------------------------------------

| Id??| Operation? ?? ???| Name? ???| Rows??| Bytes | Cost (%CPU)| Time? ???|

-----------------------------------------------------------------------------

|? ?0 | SELECT STATEMENT |? ?? ?? ? |? ???1 |? ? 13 |? ???1? ?(0)| 00:00:01 |

|*??1 |??INDEX RANGE SCAN| IND_TEST |? ???1 |? ? 13 |? ???1? ?(0)| 00:00:01 |

-----------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - access("OBJECT_ID"=32)

13 rows selected

SQL> alter table TEST

2? ? drop constraint UN_TEST cascade;

Table altered

SQL> drop index ind_test;

Index dropped

SQL> create unique index un_ind_test on test(object_id);

Index created

SQL> insert into test select * from all_objects;

insert into test select * from all_objects

ORA-00001: 違反唯一約束條件 (SCOTT.UN_IND_TEST)

SQL> explain plan for

2??select object_id from test where object_id=32;

Explained

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------

Plan hash value: 3033676969

--------------------------------------------------------------------------------

| Id??| Operation? ?? ?? ?| Name? ?? ???| Rows??| Bytes | Cost (%CPU)| Time

--------------------------------------------------------------------------------

|? ?0 | SELECT STATEMENT??|? ?? ?? ?? ? |? ???1 |? ? 13 |? ???1? ?(0)| 00:00:01

|*??1 |??INDEX UNIQUE SCAN| UN_IND_TEST |? ???1 |? ? 13 |? ???1? ?(0)| 00:00:01

--------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

1 - access("OBJECT_ID"=32)

總結(jié)

以上是生活随笔為你收集整理的oracle 唯一约束作用,想问下在表上建唯一索引和使用索引+唯一约束,从功能和性能来说有什么差别?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。