8000 Current implementation of FOR UPDATE has no hope of working correctly · danielcode/postgres@096e865 · GitHub
[go: up one dir, main page]

Skip to content

Commit 096e865

Browse files
committed
Current implementation of FOR UPDATE has no hope of working correctly
for relations on the nullable side of an OUTER JOIN. For now I think we'd better refuse such queries.
1 parent 2c632e6 commit 096e865

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/backend/optimizer/plan/initsplan.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.59 2001/04/16 19:44:10 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.59.2.1 2001/05/14 20:25:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -297,14 +297,30 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
297297

298298
foreach(relid, rels)
299299
{
300-
RelOptInfo *rel = get_base_rel(root, lfirsti(relid));
300+
int relno = lfirsti(relid);
301+
RelOptInfo *rel = get_base_rel(root, relno);
301302

302303
/*
303304
* Since we do this bottom-up, any outer-rels previously marked
304305
* should be within the new outer join set.
305306
*/
306307
Assert(is_subseti(rel->outerjoinset, outerrels));
307308

309+
/*
310+
* Presently the executor cannot support FOR UPDATE marking of
311+
* rels appearing on the nullable side of an outer join.
312+
* (It's somewhat unclear what that would mean, anyway: what should
313+
* we mark when a result row is generated from no element of the
314+
* nullable relation?) So, complain if target rel is FOR UPDATE.
315+
* It's sufficient to make this check once per rel, so do it only
316+
* if rel wasn't already known nullable.
317+
*/
318+
if (rel->outerjoinset == NIL)
319+
{
320+
if (intMember(relno, root->rowMarks))
321+
elog(ERROR, "SELECT FOR UPDATE cannot be applied to the nullable side of an OUTER JOIN");
322+
}
323+
308324
rel->outerjoinset = outerrels;
309325
}
310326
}

0 commit comments

Comments
 (0)
0