On Mon, Jun 20, 2016 at 3:33 PM, Andres Freund <and...@anarazel.de> wrote: >> I'm not sure what to do about this: this part of the heap_update() >> logic has been like this forever, and I assume that if it were easy to >> refactor this away, somebody would have done it by now. > > Well, I think generally nobody seriously looked at actually refactoring > heap_update(), even though that'd be a good idea. But in this instance, > the problem seems relatively fundamental: > > We need to lock the origin page, to do visibility checks, etc. Then we > need to figure out the target page. Even disregarding toasting - which > we could be doing earlier with some refactoring - we're going to have to > release the page level lock, to lock them in ascending order. Otherwise > we'll risk kinda likely deadlocks. We also certainly don't want to nest > the lwlocks for the toast stuff, inside a content lock for the old > tupe's page. > > So far the best idea I have - and it's really not a good one - is to > invent a new hint-bit that tells concurrent updates to acquire a > heavyweight tuple lock, while releasing the page-level lock. If that > hint bit does not require any other modifications - and we don't need an > xid in xmax for this use case - that'll avoid doing all the other > `already_marked` stuff early, which should address the correctness > issue. It's kinda invasive though, and probably has performance > implications. > > Does anybody have a better idea?
What exactly is the point of all of that already_marked stuff? I mean, suppose we just don't do any of that before we go off to do toast_insert_or_update and RelationGetBufferForTuple. Eventually, when we reacquire the page lock, we might find that somebody else has already updated the tuple, but couldn't that be handled by (approximately) looping back up to l2 just as we do in several other cases? -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-hackers mailing list (firstname.lastname@example.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers