why doesn't anyone suggest what I would obviously do? what you've seen me do over and over and over again.....
Put up or shut up, do not hypothesize about how YOU would do it, show how Oracle does it.
DML will be faster using PK on Unique
Index as it will not store rowid and hence less IO.that is not accurate, but it fortunately is not relevant to the question either :)
so, let's see:
ops$tkyte%ORA11GR2> drop table t1;
Table dropped.
ops$tkyte%ORA11GR2> drop table t2;
Table dropped.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> create table t1 ( x number constraint t_pk primary key );
Table created.
ops$tkyte%ORA11GR2> create table t2 ( y number not null );
Table created.
ops$tkyte%ORA11GR2> create UNIQUE index t2_idx on t2(y);
Index created.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> @trace
ops$tkyte%ORA11GR2> alter session set events '10046 trace name context forever, level 12';
Session altered.
ops$tkyte%ORA11GR2> select to_char(sysdate,'dd-mon-yyyy hh24:mi:ss' ) from dual;
TO_CHAR(SYSDATE,'DD-
--------------------
23-apr-2010 09:55:36
ops$tkyte%ORA11GR2> begin
2 for i in 1 .. 100000
3 loop
4 insert into t1 (x) values ( i );
5 insert into t2 (y) values ( i );
6 end loop;
7 insert into t1 (x)
8 select 100000+rownum
9 from dual
10 connect by level < 100000;
11 insert into t2 (y)
12 select 100000+rownum
13 from dual
14 connect by level < 100000;
15 end;
16 /
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> select to_char(sysdate,'dd-mon-yyyy hh24:mi:ss' ) from dual;
TO_CHAR(SYSDATE,'DD-
--------------------
23-apr-2010 09:56:45
ops$tkyte%ORA11GR2> @tk "sys=no"
ops$tkyte%ORA11GR2> column trace new_val TRACE
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> select c.value || '/' || d.instance_name || '_ora_' || a.spid || '.trc' trace
2 from v$process a, v$session b, v$parameter c, v$instance d
3 where a.addr = b.paddr
4 and b.audsid = userenv('sessionid')
5 and c.name = 'user_dump_dest'
6 /
TRACE
-------------------------------------------------------------------------------
/home/ora11gr2/app/ora11gr2/diag/rdbms/orcl/ora11gr2/trace/ora11gr2_ora_24921.t
rc
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ops$tkyte%ORA11GR2> !tkprof &TRACE ./tk.prf &1
TKPROF: Release 11.2.0.1.0 - Development on Fri Apr 23 09:56:47 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
ops$tkyte%ORA11GR2> connect /
Connected.
ops$tkyte%ORA11GR2> edit tk.prf
INSERT INTO T1 (X) VALUES ( :B1 )
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 99999 21.42 22.77 10 780 309266 99999
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 100000 21.42 22.77 10 780 309266 99999
********************************************************************************
INSERT INTO T2 (Y) VALUES ( :B1 )
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 99999 21.31 22.76 15 779 309247 99999
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 100000 21.31 22.76 15 779 309247 99999
********************************************************************************
INSERT INTO T1 (X) SELECT 100000+ROWNUM FROM DUAL CONNECT BY LEVEL < 100000
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.03 0 0 0 0
Execute 1 0.61 2.00 31 704 6514 99999
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.61 2.03 31 704 6514 99999
********************************************************************************
INSERT INTO T2 (Y) SELECT 100000+ROWNUM FROM DUAL CONNECT BY LEVEL < 100000
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.63 2.69 50 700 6489 99999
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.63 2.70 50 700 6489 99999
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> exec runStats_pkg.rs_start;
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> begin
2 for i in 200000 .. 300000
3 loop
4 insert into t1 (x) values ( i );
5 end loop;
6 insert into t1 (x)
7 select 300000+rownum
8 from dual
9 connect by level < 100000;
10 end;
11 /
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> exec runStats_pkg.rs_middle;
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> begin
2 for i in 200000 .. 300000
3 loop
4 insert into t2 (y) values ( i );
5 end loop;
6 insert into t2 (y)
7 select 300000+rownum
8 from dual
9 connect by level < 100000;
10 end;
11 /
PL/SQL procedure successfully completed.
ops$tkyte%ORA11GR2> exec runStats_pkg.rs_stop(5000);
Run1 ran in 779 cpu hsecs
Run2 ran in 735 cpu hsecs
run 1 ran in 105.99% of the time
Name Run1 Run2 Diff
STAT...redo size 57,682,208 57,676,944 -5,264
STAT...file io wait time 2,741 9,079 6,338
LATCH.JS slv state obj latch -64,268 1 64,269
STAT...session uga memory 0 65,512 65,512
STAT...session cursor cache hi 34,495 -31,051 -65,546
STAT...physical read bytes 466,944 622,592 155,648
STAT...physical read total byt 466,944 622,592 155,648
STAT...cell physical IO interc 466,944 622,592 155,648
STAT...session pga memory -17,028 327,680 344,708
STAT...session uga memory max 1,952,852 0 -1,952,852
STAT...session pga memory max 2,407,804 0 -2,407,804
Run1 latches total versus runs -- difference and pct
Run1 Run2 Diff Pct
1,462,344 1,526,381 64,037 95.80%
PL/SQL procedure successfully completed.
Nope, doesn't look like it to me - does it look like it to you?
Use the primary key constraint - and tell this other person to have some form of evidence that what they say is probably true before they say it - it'll not only save time but will make them look better going forward :)