postgres.git / summary / log / commit / refs
commit f5e4e92fbe2fd655d8b1ec30b523cfb134e66bf0
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri Dec 12 00:37:17 2014 +0000
First released in: 9.5.0, 9.0.19, 9.1.15, 9.2.10, 9.3.6, 9.4.0
Fix corner case where SELECT FOR UPDATE could return a row twice.
In READ COMMITTED mode, if a SELECT FOR UPDATE discovers it has to redo
WHERE-clause checking on rows that have been updated since the SELECT's
snapshot, it invokes EvalPlanQual processing to do that. If this first
occurs within a non-first child table of an inheritance tree, the previous
coding could accidentally re-return a matching row from an earlier,
already-scanned child table. (And, to add insult to injury, I think this
could make it miss returning a row that should have been returned, if the
updated row that this happens on should still have passed the WHERE qual.)
Per report from Kyotaro Horiguchi; the added isolation test is based on his
test case.
This has been broken for quite awhile, so back-patch to all supported
branches.
src/backend/executor/nodeLockRows.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/backend/executor/nodeLockRows.c b/src/backend/executor/nodeLockRows.c
index b9967c92904..2f4d2ed6ce3 100644
--- a/src/backend/executor/nodeLockRows.c
+++ b/src/backend/executor/nodeLockRows.c
@@ -160,7 +160,29 @@ lnext:
*/
if (!epq_started)
{
+ ListCell *lc2;
+
EvalPlanQualBegin(&node->lr_epqstate, estate);
+
+ /*
+ * Ensure that rels with already-visited rowmarks are told
+ * not to return tuples during the first EPQ test. We can
+ * exit this loop once it reaches the current rowmark;
+ * rels appearing later in the list will be set up
+ * correctly by the EvalPlanQualSetTuple call at the top
+ * of the loop.
+ */
+ foreach(lc2, node->lr_arowMarks)
+ {
+ ExecAuxRowMark *aerm2 = (ExecAuxRowMark *) lfirst(lc2);
+
+ if (lc2 == lc)
+ break;
+ EvalPlanQualSetTuple(&node->lr_epqstate,
+ aerm2->rowmark->rti,
+ NULL);
+ }
+
epq_started = true;
}
[parent: d67be559ed8a]