postgresql/src
Tom Lane 81ee435c42 Fix subtransaction cleanup after an outer-subtransaction portal fails.
Formerly, we treated only portals created in the current subtransaction as
having failed during subtransaction abort.  However, if the error occurred
while running a portal created in an outer subtransaction (ie, a cursor
declared before the last savepoint), that has to be considered broken too.

To allow reliable detection of which ones those are, add a bookkeeping
field to struct Portal that tracks the innermost subtransaction in which
each portal has actually been executed.  (Without this, we'd end up
failing portals containing functions that had called the subtransaction,
thereby breaking plpgsql exception blocks completely.)

In addition, when we fail an outer-subtransaction Portal, transfer its
resources into the subtransaction's resource owner, so that they're
released early in cleanup of the subxact.  This fixes a problem reported by
Jim Nasby in which a function executed in an outer-subtransaction cursor
could cause an Assert failure or crash by referencing a relation created
within the inner subtransaction.

The proximate cause of the Assert failure is that AtEOSubXact_RelationCache
assumed it could blow away a relcache entry without first checking that the
entry had zero refcount.  That was a bad idea on its own terms, so add such
a check there, and to the similar coding in AtEOXact_RelationCache.  This
provides an independent safety measure in case there are still ways to
provoke the situation despite the Portal-level changes.

This has been broken since subtransactions were invented, so back-patch
to all supported branches.

Tom Lane and Michael Paquier
2015-09-04 13:36:50 -04:00
..
backend Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:36:50 -04:00
bin Fix privilege dumping from servers too old to have that type of privilege. 2015-08-10 20:10:16 -04:00
include Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:36:50 -04:00
interfaces Fix declaration of isarray variable. 2015-08-13 13:26:32 +02:00
makefiles Don't use deprecated dllwrap on Cygwin. 2014-02-01 16:14:15 -05:00
pl Fix a few bogus statement type names in plpgsql error messages. 2015-08-18 19:22:38 -04:00
port Fix a low-probability crash in our qsort implementation. 2015-07-16 22:57:46 -04:00
template AIX: Test the -qlonglong option before use. 2015-07-17 03:02:46 -04:00
test Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:36:50 -04:00
timezone Update time zone data files to tzdata release 2015d. 2015-05-15 19:36:20 -04:00
tools Turn install.bat into a pure one line wrapper fort he perl script. 2015-07-07 16:39:25 +03:00
tutorial Remove tabs after spaces in C comments 2014-05-06 11:26:25 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:06 +02:00
bcc32.mak Remove old-style win32 client-only visual c++ build infrastructure for everything except 2007-03-05 14:18:38 +00:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Rethink the way walreceiver is linked into the backend. Instead than shoving 2010-01-20 09:16:24 +00:00
Makefile.global.in Make numeric form of PG version number readily available in Makefiles. 2015-07-05 12:01:02 -04:00
Makefile.shlib Unlink static libraries before rebuilding them. 2015-03-01 13:08:48 -05:00
nls-global.mk Avoid error from mkdir if no languages are to be installed 2010-05-13 14:35:28 +00:00
win32.mak Update supported standalone VC++ version to 7.1+ only, and fix 2007-08-03 10:47:11 +00:00