Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: select + insert vs. insert and catching exception
How often is it going to happen ?
How often is it likely to fail on insert ?
If the task runs rarely, who cares about a marginal overhead. If the task runs very frequently and the select usually succeeds then do the select first. If the task runs very frequently and the insert usually succeeds (at least 19 times out of 20) then consider doing the insert first.
Inserting and getting a constraint breached is much more expensive than doing a single select which returns no rows.
(Would you be doing an update if the select succeeds ? If so why not:
update
if no rows updated
insert
-- Regards Jonathan Lewis http://www.jlcomp.demon.co.uk Next Seminar dates: (see http://www.jlcomp.demon.co.uk/seminar.html ) ____England______September 24/26, November 12/14 ____USA__________November 7/9 (MI), 19/21 (TX) The Co-operative Oracle Users' FAQ http://www.jlcomp.demon.co.uk/faq/ind_faq.html Christoph Seidel wrote in message ...Received on Thu Sep 26 2002 - 14:26:38 CDT
>what is better in respect of performance?
>
>select by primary key, if not found insert
>
>or
>
>insert and catch exception if primary key exists
>
>the table is quite small, less than 100 rows
>
>