From: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> |
---|---|
To: | Simon Riggs <simon(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)2ndquadrant(dot)com>, "Peter Geoghegan" <pg(at)heroku(dot)com> |
Subject: | Re: Promise index tuples for UPSERT |
Date: | 2014-10-01 19:54:22 |
Message-ID: | 542C5BEE.3090901@vmware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 10/01/2014 02:34 PM, Simon Riggs wrote:
> Summary of algorithm to use "promise tuples" for concurrency control
> during UPSERT
>
> 1. Perform btree search to location of key, if it exists.
> a) If an unkilled index tuple exists, we decide this is an UPDATE and
> drop straight thru to step 2
> b) If it does not exist, insert a "promise" tuple into unique index(s)
> - marked with the xid of the inserting transaction, but using the key.
> This happens while the page is locked, so it is not possible to insert
> a second promise tuple concurrently.
> Record the btree blockid on the index scan and move to step 3
> When later insert scans see the promise tuple they perform
> XactLockTableWait() and when they get control they look again for the
> key. If they find a promise tuple with an aborted xid they replace
> that value with their own xid and continue as a). Otherwise b).
XactLockTableWait() waits until the end of transaction, that's not you
want here. If the backend that inserted the promise tuple decides to not
proceed with the insertion, and removes the promise tuple, the backend
waiting on it needs to be woken up more or less immediately, not when
the transaction completes.
I had this exact same issue in my earlier patch versions, fixed it with
a new kind of heavy-weight lock, and a new field in PGPROC
(http://www.postgresql.org/message-id/52D00D2D.6030307@vmware.com) That
wasn't very pretty, but it got the job done. Some other design might be
better.
- Heikki
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Geoghegan | 2014-10-01 19:58:08 | Re: Promise index tuples for UPSERT |
Previous Message | Robert Haas | 2014-10-01 19:09:22 | Re: autovacuum scheduling starvation and frenzy |