Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: select + insert vs. insert and catching exception

Re: select + insert vs. insert and catching exception

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Thu, 26 Sep 2002 20:26:38 +0100
Message-ID: <amvn1b$k24$1$8300dec7@news.demon.co.uk>

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 ...

>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
>
>
Received on Thu Sep 26 2002 - 14:26:38 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US