diff options
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r-- | src/backend/executor/spi.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 59f77471432..74f64f8fed1 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -328,13 +328,13 @@ _SPI_rollback(bool chain) { MemoryContext oldcontext = CurrentMemoryContext; - /* see under SPI_commit() */ + /* see comments in _SPI_commit() */ if (_SPI_current->atomic) ereport(ERROR, (errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION), errmsg("invalid transaction termination"))); - /* see under SPI_commit() */ + /* see comments in _SPI_commit() */ if (IsSubTransaction()) ereport(ERROR, (errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION), @@ -587,8 +587,11 @@ SPI_inside_nonatomic_context(void) { if (_SPI_current == NULL) return false; /* not in any SPI context at all */ + /* these tests must match _SPI_commit's opinion of what's atomic: */ if (_SPI_current->atomic) return false; /* it's atomic (ie function not procedure) */ + if (IsSubTransaction()) + return false; /* if within subtransaction, it's atomic */ return true; } @@ -2217,9 +2220,12 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, /* * We allow nonatomic behavior only if plan->no_snapshots is set - * *and* the SPI_OPT_NONATOMIC flag was given when connecting. + * *and* the SPI_OPT_NONATOMIC flag was given when connecting and we are + * not inside a subtransaction. The latter two tests match whether + * _SPI_commit() would allow a commit; see there for more commentary. */ - allow_nonatomic = plan->no_snapshots && !_SPI_current->atomic; + allow_nonatomic = plan->no_snapshots && + !_SPI_current->atomic && !IsSubTransaction(); /* * Setup error traceback support for ereport() |