Re: Remembering bug #6123
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Kevin Grittner" <Kevin.Grittner@wicourts.gov>
Cc: pgsql-hackers@postgresql.org
Date: 2012-01-22T21:04:31Z
Lists: pgsql-hackers
Attachments
- bug6123-v8.patch (text/x-patch) patch v8
OK, here's an updated version of the patch. I changed the error message texts as per discussion (except I decided to use one message string for all the cases rather than saddle translators with several variants). Also, I put in an error in GetTupleForTrigger, which fixes the self-reference case I illustrated before (now added to the regression test). However, I found out that changing the other two callers of heap_lock_tuple would open an entirely new can of worms, so for now they still have the historical behavior of ignoring self-updated tuples. The problem with changing ExecLockRows or EvalPlanQualFetch can be illustrated by the regression test case it breaks, which basically is BEGIN; DECLARE c1 CURSOR FOR SELECT * FROM table FOR UPDATE; UPDATE table SET ...; FETCH ALL FROM c1; COMMIT; When the FETCH comes to a row that's been updated by the UPDATE, it sees that row as HeapTupleSelfUpdated with a cmax greater than es_output_cid (which is the CID assigned to the DECLARE). So if we make these callers throw an error for the case, coding like the above will fail, which seems to me to be pretty darn hard to justify. It is not a corner case that could be caused only by questionable use of trigger side effects. So that seems to leave us with two choices: (1) ignore the row, or (2) attempt to lock the latest version instead of the visible version. (1) is our historical behavior but seems arguably wrong. I tried to make the patch do (2) but it crashed and burned because heap_lock_tuple spits up if asked to lock an "invisible" row. We could possibly finesse that by having EvalPlanQualFetch sometimes pass a CID later than es_output_cid to heap_lock_tuple, but it seems ticklish. More, I think it would also take some adjustments to the behavior of HeapTupleSatisfiesDirty, else we'll not see such tuples in the first place. So this looks messy, and also rather orthogonal to the current goals of the patch. Also, I'm not sure that your testing would exercise such cases at all, as you have to be using SELECT FOR UPDATE and/or READ COMMITTED mode to get to any of the relevant code. I gather your software mostly relies on SERIALIZABLE mode to avoid such issues. So I stopped with this. regards, tom lane