]> granicus.if.org Git - postgresql/commit
When FOR UPDATE/SHARE is used with LIMIT, put the LockRows plan node
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 28 Oct 2009 14:55:47 +0000 (14:55 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 28 Oct 2009 14:55:47 +0000 (14:55 +0000)
commit46e3a16b050a23b924e5d8a75c8bb7068c26aa96
tree3832d199195ba326e6a3a1a2f48534dd83a9bddc
parent44956c52c5fef0b2bb541e959bd65910949eb15f
When FOR UPDATE/SHARE is used with LIMIT, put the LockRows plan node
underneath the Limit node, not atop it.  This fixes the old problem that such
a query might unexpectedly return fewer rows than the LIMIT says, due to
LockRows discarding updated rows.

There is a related problem that LockRows might destroy the sort ordering
produced by earlier steps; but fixing that by pushing LockRows below Sort
would create serious performance problems that are unjustified in many
real-world applications, as well as potential deadlock problems from locking
many more rows than expected.  Instead, keep the present semantics of applying
FOR UPDATE after ORDER BY within a single query level; but allow the user to
specify the other way by writing FOR UPDATE in a sub-select.  To make that
work, track whether FOR UPDATE appeared explicitly in sub-selects or got
pushed down from the parent, and don't flatten a sub-select that contained an
explicit FOR UPDATE.
13 files changed:
doc/src/sgml/ref/select.sgml
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/prep/prepjointree.c
src/backend/parser/analyze.c
src/backend/rewrite/rewriteHandler.c
src/backend/utils/adt/ruleutils.c
src/include/catalog/catversion.h
src/include/nodes/parsenodes.h
src/include/parser/analyze.h