Re: update/insert, delete/insert efficiency WRT vacuum

From: Hannu Krosing <hannu(at)skype(dot)net>
To: Zeugswetter Andreas DCP SD <ZeugswetterA(at)spardat(dot)at>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, Zdenek Kotala <Zdenek(dot)Kotala(at)Sun(dot)COM>, Mark Woodward <pgsql(at)mohawksoft(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: update/insert, delete/insert efficiency WRT vacuum
Date: 2006-07-04 22:45:59
Message-ID: 1152053160.3094.1.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ühel kenal päeval, T, 2006-07-04 kell 14:53, kirjutas Zeugswetter
Andreas DCP SD:
> > > >Is there a difference in PostgreSQL performance between these two
> > > >different strategies:
> > > >
> > > >
> > > >if(!exec("update foo set bar='blahblah' where name = 'xx'"))
> > > > exec("insert into foo(name, bar) values('xx','blahblah'"); or
>
> In pg, this strategy is generally more efficient, since a pk failing
> insert would create
> a tx abort and a heap tuple. (so in pg, I would choose the insert first
> strategy only when
> the insert succeeds most of the time (say > 95%))
>
> Note however that the above error handling is not enough, because two
> different sessions
> can still both end up trying the insert (This is true for all db systems
> when using this strategy).

I think the recommended strategy is to first try tu UPDATE, if not found
then INSERT, if primary key violation on insert, then UPDATE

--
----------------
Hannu Krosing
Database Architect
Skype Technologies OÜ
Akadeemia tee 21 F, Tallinn, 12618, Estonia

Skype me: callto:hkrosing
Get Skype for free: http://www.skype.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Mair 2006-07-05 05:14:54 Re: buildfarm stats
Previous Message Tom Lane 2006-07-04 21:40:07 Re: passing parameters to CREATE INDEX