aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeLockRows.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-12-11 19:37:00 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-12-11 19:37:36 -0500
commit2db576ba8c449fcaf61ae7aa14ed62e63ebf5924 (patch)
treeb52d0c09ff79a8852ae6c0280c68cb9a6b80cab3 /src/backend/executor/nodeLockRows.c
parent2646d2d4a9d8b978fda0d0d1affae4788a30f604 (diff)
downloadpostgresql-2db576ba8c449fcaf61ae7aa14ed62e63ebf5924.tar.gz
postgresql-2db576ba8c449fcaf61ae7aa14ed62e63ebf5924.zip
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.
Diffstat (limited to 'src/backend/executor/nodeLockRows.c')
-rw-r--r--src/backend/executor/nodeLockRows.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/executor/nodeLockRows.c b/src/backend/executor/nodeLockRows.c
index 990240bf0a8..5dcb9b042ac 100644
--- a/src/backend/executor/nodeLockRows.c
+++ b/src/backend/executor/nodeLockRows.c
@@ -194,7 +194,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;
}