postgresql/src
Tom Lane 9e9b310d8b 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 psql: print longtable as a possible \pset option 2015-08-31 12:24:16 -04:00
common Unlink static libraries before rebuilding them. 2015-03-01 13:06:39 -05: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:25:45 +02:00
makefiles Don't use deprecated dllwrap on Cygwin. 2014-02-01 16:13:32 -05:00
pl Fix plpython crash when returning string representation of a RECORD result. 2015-08-21 12:21:37 -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:03 -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:35:58 -04:00
tools Turn install.bat into a pure one line wrapper fort he perl script. 2015-07-07 16:37:16 +03:00
tutorial Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04: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 Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Make numeric form of PG version number readily available in Makefiles. 2015-07-05 12:01:01 -04:00
Makefile.shlib Unlink static libraries before rebuilding them. 2015-03-01 13:06:39 -05:00
nls-global.mk NLS: Use msgmerge --previous option 2012-12-13 23:12:12 -05:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00