postgresql/src/include/executor
Tom Lane 485d49dbc9 Fix crash when logical decoding is invoked from a PL function.
The logical decoding functions do BeginInternalSubTransaction and
RollbackAndReleaseCurrentSubTransaction to clean up after themselves.
It turns out that AtEOSubXact_SPI has an unrecognized assumption that
we always need to cancel the active SPI operation in the SPI context
that surrounds the subtransaction (if there is one).  That's true
when the RollbackAndReleaseCurrentSubTransaction call is coming from
the SPI-using function itself, but not when it's happening inside
some unrelated function invoked by a SPI query.  In practice the
affected callers are the various PLs.

To fix, record the current subtransaction ID when we begin a SPI
operation, and clean up only if that ID is the subtransaction being
canceled.

Also, remove AtEOSubXact_SPI's assertion that it must have cleaned
up the surrounding SPI context's active tuptable.  That's proven
wrong by the same test case.

Also clarify (or, if you prefer, reinterpret) the calling conventions
for _SPI_begin_call and _SPI_end_call.  The memory context cleanup
in the latter means that these have always had the flavor of a matched
resource-management pair, but they weren't documented that way before.

Per report from Ben Chobot.

Back-patch to 9.4 where logical decoding came in.  In principle,
the SPI changes should go all the way back, since the problem dates
back to commit 7ec1c5a86.  But given the lack of field complaints
it seems few people are using internal subtransactions in this way.
So I don't feel a need to take any risks in 9.2/9.3.

Discussion: https://postgr.es/m/73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com
2017-10-06 19:18:58 -04:00
..
execdebug.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
execdesc.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
execExpr.h Code review for NextValueExpr expression node type. 2017-07-14 15:25:43 -04:00
execParallel.h Improve division of labor between execParallel.c and nodeGather[Merge].c. 2017-09-01 17:38:54 -04:00
executor.h Even if some partitions are foreign, allow tuple routing. 2017-09-07 10:59:28 -04:00
functions.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
hashjoin.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
instrument.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nodeAgg.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeAppend.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeBitmapAnd.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nodeBitmapHeapscan.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeBitmapIndexscan.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nodeBitmapOr.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nodeCtescan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeCustom.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeForeignscan.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeFunctionscan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeGather.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeGatherMerge.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeGroup.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeHash.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeHashjoin.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeIndexonlyscan.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeIndexscan.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeLimit.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeLockRows.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeMaterial.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeMergeAppend.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeMergejoin.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeModifyTable.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeNamedtuplestorescan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeNestloop.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeProjectSet.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeRecursiveunion.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeResult.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeSamplescan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeSeqscan.h Separate reinitialization of shared parallel-scan state from ExecReScan. 2017-08-30 13:18:16 -04:00
nodeSetOp.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeSort.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeSubplan.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
nodeSubqueryscan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeTableFuncscan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeTidscan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeUnique.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeValuesscan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeWindowAgg.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
nodeWorktablescan.h Move ExecProcNode from dispatch to function pointer based model. 2017-07-30 16:18:21 -07:00
spi.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
spi_priv.h Fix crash when logical decoding is invoked from a PL function. 2017-10-06 19:18:58 -04:00
tablefunc.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tqueue.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tstoreReceiver.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
tuptable.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00