faster INSERT with possible pre-existing row? - Mailing list pgsql-performance

From Dan Harris
Subject faster INSERT with possible pre-existing row?
Date
Msg-id AB60A4E4-1DF1-459E-8866-007810D68419@drivefaster.net
Whole thread Raw
Responses Re: faster INSERT with possible pre-existing row?  (John A Meinel <john@arbash-meinel.com>)
Re: faster INSERT with possible pre-existing row?  (Sven Willenberger <sven@dmv.com>)
Re: faster INSERT with possible pre-existing row?  (Matthew Nuzum <mattnuzum@gmail.com>)
Re: faster INSERT with possible pre-existing row?  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
List pgsql-performance
I am working on a process that will be inserting tens of million rows
and need this to be as quick as possible.

The catch is that for each row I could potentially insert, I need to
look and see if the relationship is already there  to prevent
multiple entries.  Currently I am doing a SELECT before doing the
INSERT, but I recognize the speed penalty in doing to operations.  I
wonder if there is some way I can say "insert this record, only if it
doesn't exist already".  To see if it exists, I would need to compare
3 fields instead of just enforcing a primary key.

Even if this could be a small increase per record, even a few percent
faster compounded over the whole load could be a significant reduction.

Thanks for any ideas you might have.

-Dan

pgsql-performance by date:

Previous
From: John A Meinel
Date:
Subject: Cheap RAM disk?
Next
From: Chris Browne
Date:
Subject: Re: Cheap RAM disk?