pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Anton Maksimenkov <engineer@hlebprom.ru>
Cc: pgsql-performance@postgresql.org
Subject: Re: DELETE, INSERT vs SELECT, UPDATE || INSERT
Date: Fri, 23 Dec 2005 10:30:00 -0500
Message-ID: <19921.1135351800@sss.pgh.pa.us> (raw)
In-Reply-To: <287988431.20051223140205@hlebprom.ru>
References: <287988431.20051223140205@hlebprom.ru>

Anton Maksimenkov <engineer@hlebprom.ru> writes:
>  Second idea was to try to SELECT (user, cookie) pair and then UPDATE
> it if it exists or INSERT if not. I has thought that if UPDATE will
> rewrite same place in file with new count it may lead to more compact
> table (file not grow and information about actual rows in file will
> not changed).

You're wasting your time, because Postgres doesn't work that way.
UPDATE is really indistinguishable from DELETE+INSERT, and there will
always be a dead row afterwards, because under MVCC rules both versions
of the row have to be left in the table for some time after your
transaction commits.  See
http://www.postgresql.org/docs/8.1/static/mvcc.html

			regards, tom lane



view thread (2+ messages)

Message-ID: <19921.1135351800@sss.pgh.pa.us>
Permalink:  ../19921.1135351800@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19921.1135351800@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, engineer@hlebprom.ru
  Subject: Re: DELETE, INSERT vs SELECT, UPDATE || INSERT
  In-Reply-To: <19921.1135351800@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox