Re: Promise index tuples for UPSERT - Mailing list pgsql-hackers

From Simon Riggs
Subject Re: Promise index tuples for UPSERT
Date
Msg-id CA+U5nMLqQZsqamMQdWSSLw-GgNi=ry_znX7hg3oiYTtRdGm3EA@mail.gmail.com
Whole thread Raw
In response to Re: Promise index tuples for UPSERT  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Responses Re: Promise index tuples for UPSERT
List pgsql-hackers
On 6 October 2014 13:21, Heikki Linnakangas <hlinnakangas@vmware.com> wrote:

>> My understanding of what you're saying is that if
>>
>> * we have a table with >1 unique index
>> * and we update the values of the uniquely index columns (e.g. PK update)
>> * on both of the uniquely indexed column sets
>> then we get occaisonal deadlocks, just as we would do using current
>> UPDATE/INSERT.
>
>
> Right. To be precise: you don't need to update both of the columns in the
> same transaction, it's enough that some of the concurrent transactions
> update one column, while other transactions update the other column.

CREATE TABLE foo
(id1    integer not null primary key
,id2    integer not null unique
,val    integer);

Given the table above, which one do we mean?

1. When we mix UPDATE foo SET id2 = X WHERE id1 = Y;  and UPDATE foo
SET id1 = Y WHERE id2 = X; we can deadlock
2. When we mix UPDATE foo SET val = Z WHERE id1 = Y;  and UPDATE foo
SET val = W WHERE id2 = X; we can deadlock

(2) is a common use case, (1) is a very rare use case and most likely
a poor design

If the user wishes to protect against such deadlocks they retain the
option to use row locking. Yes?

-- Simon Riggs                   http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Fabrízio de Royes Mello
Date:
Subject: Re: CREATE IF NOT EXISTS INDEX
Next
From: Tom Lane
Date:
Subject: Re: Failure with make check-world for pgtypeslib/dt_test2 with HEAD on OSX