Re: Performance Implications of Using Exceptions

From: James Mansion <james(at)mansionfamily(dot)plus(dot)com>
To: Robins Tharakan <tharakan(at)gmail(dot)com>
Cc: chemuduguntar(at)gmail(dot)com, pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance Implications of Using Exceptions
Date: 2008-04-06 20:21:41
Message-ID: 47F930D5.5030607@mansionfamily.plus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Robins Tharakan wrote:
>
> I think James was talking about Sybase. Postgresql on the other hand
> has a slightly better way to do this.
>
> SELECT ... FOR UPDATE allows you to lock a given row (based on the
> SELECT ... WHERE clause) and update it... without worrying about a
> concurrent modification. Of course, if the SELECT ... WHERE didn't
> bring up any rows, you would need to do an INSERT anyway.
How does that help?

If the matching row doesn't exist at that point - what is there to get
locked?

The problem is that you need to effectively assert a lock on the primary
key so that you can update
the row (if it exists) or insert a row with that key (if it doesn't)
without checking and then inserting and
finding that some other guy you were racing performed the insert and you
get a duplicate key error.

How does Postgresql protect against this?

James

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Ow Mun Heng 2008-04-07 08:15:51 Forcing more agressive index scans for BITMAP AND
Previous Message Tom Lane 2008-04-05 04:20:43 Re: Query plan excluding index on view