oracle 唯一约束作用,想问下在表上建唯一索引和使用索引+唯一约束,从功能和性能来说有什么差别?...
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle有text字段吗,Oracl
- 下一篇: oracle中的char和j,oracl