postgres/src/backend/commands
Tom Lane 39ebb64669 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
..
aggregatecmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
alter.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
analyze.c Add vacuum_delay_point call in compute_index_stats's per-sample-row loop. 2015-03-29 15:04:28 -04:00
async.c Fix volatile-safety issue in asyncQueueReadAllNotifications(). 2015-01-26 11:57:42 -05:00
cluster.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
collationcmds.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
comment.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
constraint.c Fix incorrect checking of deferred exclusion constraint after a HOT update. 2015-05-11 12:25:28 -04:00
conversioncmds.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
copy.c Be more careful to not lose sync in the FE/BE protocol. 2015-02-02 17:09:35 +02:00
createas.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
dbcommands.c Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE. 2014-11-04 13:24:17 -05:00
define.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
discard.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
dropcmds.c Don't trash input list structure in does_not_exist_skipping(). 2012-11-08 11:34:37 -05:00
explain.c Prevent auto_explain from changing the output of a user's EXPLAIN. 2014-05-20 12:20:57 -04:00
extension.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
foreigncmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
functioncmds.c Fix pg_get_functiondef() to print a function's LEAKPROOF property. 2015-05-28 11:24:37 -04:00
indexcmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
lockcmds.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
Makefile Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. 2012-03-19 21:38:12 -04:00
opclasscmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
operatorcmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
portalcmds.c Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:36:50 -04:00
prepare.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
proclang.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
schemacmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
seclabel.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
sequence.c Reconsider when to wait for WAL flushes/syncrep during commit. 2015-02-26 12:50:07 +01:00
tablecmds.c Improve error message and hint for ALTER COLUMN TYPE can't-cast failure. 2015-06-12 11:54:03 -04:00
tablespace.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
trigger.c Fix column-privilege leak in error-message paths 2015-01-28 12:32:56 -05:00
tsearchcmds.c Fix REASSIGN OWNED for text search objects 2014-07-15 13:24:07 -04:00
typecmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
user.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
vacuum.c Reject ANALYZE commands during VACUUM FULL or another ANALYZE. 2015-01-07 22:34:26 -05:00
vacuumlazy.c Test IsInTransactionChain, not IsTransactionBlock, in vac_update_relstats. 2014-10-30 13:03:31 -04:00
variable.c Reject out-of-range numeric timezone specifications. 2014-07-21 22:41:30 -04:00
view.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00