postgresql/src/include/utils
Tom Lane 41c6a5bec2 Restore the portal-level snapshot after procedure COMMIT/ROLLBACK.
COMMIT/ROLLBACK necessarily destroys all snapshots within the session.
The original implementation of intra-procedure transactions just
cavalierly did that, ignoring the fact that this left us executing in
a rather different environment than normal.  In particular, it turns
out that handling of toasted datums depends rather critically on there
being an outer ActiveSnapshot: otherwise, when SPI or the core
executor pop whatever snapshot they used and return, it's unsafe to
dereference any toasted datums that may appear in the query result.
It's possible to demonstrate "no known snapshots" and "missing chunk
number N for toast value" errors as a result of this oversight.

Historically this outer snapshot has been held by the Portal code,
and that seems like a good plan to preserve.  So add infrastructure
to pquery.c to allow re-establishing the Portal-owned snapshot if it's
not there anymore, and add enough bookkeeping support that we can tell
whether it is or not.

We can't, however, just re-establish the Portal snapshot as part of
COMMIT/ROLLBACK.  As in normal transaction start, acquiring the first
snapshot should wait until after SET and LOCK commands.  Hence, teach
spi.c about doing this at the right time.  (Note that this patch
doesn't fix the problem for any PLs that try to run intra-procedure
transactions without using SPI to execute SQL commands.)

This makes SPI's no_snapshots parameter rather a misnomer, so in HEAD,
rename that to allow_nonatomic.

replication/logical/worker.c also needs some fixes, because it wasn't
careful to hold a snapshot open around AFTER trigger execution.
That code doesn't use a Portal, which I suspect someday we're gonna
have to fix.  But for now, just rearrange the order of operations.
This includes back-patching the recent addition of finish_estate()
to centralize the cleanup logic there.

This also back-patches commit 2ecfeda3e into v13, to improve the
test coverage for worker.c (it was that test that exposed that
worker.c's snapshot management is wrong).

Per bug #15990 from Andreas Wicht.  Back-patch to v11 where
intra-procedure COMMIT was added.

Discussion: https://postgr.es/m/15990-eee2ac466b11293d@postgresql.org
2021-05-21 14:03:53 -04:00
..
.gitignore Revert "Add gitignore entries for jsonpath_gram.h" 2019-03-23 00:19:34 +01:00
acl.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
aclchk_internal.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
array.h Prevent integer overflows in array subscripting calculations. 2021-05-10 10:44:38 -04:00
arrayaccess.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:17 -07:00
ascii.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
attoptcache.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
builtins.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
bytea.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
cash.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
catcache.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
combocid.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
date.h Reject "23:59:60.nnn" in datetime input. 2020-06-04 16:42:08 -04:00
datetime.h Remove explicit error handling for obsolete date/time values 2019-06-30 10:27:35 +02:00
datum.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
dsa.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
dynahash.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
elog.h Re-implement the ereport() macro using __VA_ARGS__. 2020-03-24 11:48:33 -04:00
evtcache.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
expandeddatum.h Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:17 -07:00
expandedrecord.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
float.h Avoid a performance regression in float overflow/underflow detection. 2020-02-13 13:37:43 -05:00
fmgrtab.h Reduce the size of the fmgr_builtin_oid_index[] array. 2019-01-09 15:22:43 -05:00
formatting.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
freepage.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
geo_decls.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
guc.h Revert "Add log_statement_sample_rate parameter" 2019-08-04 23:37:44 +02:00
guc_tables.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
hashutils.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
help_config.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
hsearch.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
index_selfuncs.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
inet.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
int8.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
inval.h Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
json.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
jsonapi.h Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
jsonb.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
jsonpath.h Fix bogus handling of XQuery regex option flags. 2019-09-17 15:39:51 -04:00
logtape.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
lsyscache.h Preserve pg_attribute.attstattarget across REINDEX CONCURRENTLY 2021-02-10 13:09:12 +09:00
memdebug.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
memutils.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
numeric.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
palloc.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
partcache.h Move code for managing PartitionDescs into a new file, partdesc.c 2019-02-21 11:45:02 -05:00
pg_crc.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pg_locale.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
pg_lsn.h Don't call data type input functions in GUC check hooks 2019-06-30 10:27:43 +02:00
pg_rusage.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
pidfile.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
plancache.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
portal.h Restore the portal-level snapshot after procedure COMMIT/ROLLBACK. 2021-05-21 14:03:53 -04:00
ps_status.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
queryenvironment.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
rangetypes.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
regproc.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
rel.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
relcache.h Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
relfilenodemap.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
relmapper.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
relptr.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
reltrigger.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
resowner.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
resowner_private.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
rls.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
ruleutils.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
sampling.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
selfuncs.h Use query collation, not column's collation, while examining statistics. 2020-06-05 16:18:50 -04:00
sharedtuplestore.h Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
snapmgr.h Avoid catalog lookups in RelationAllowsEarlyPruning(). 2019-08-28 16:18:39 +12:00
snapshot.h Fix double-word typos 2019-06-13 10:03:56 -04:00
sortsupport.h Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
spccache.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
syscache.h Rework the pg_statistic_ext catalog 2019-06-16 01:20:31 +02:00
timeout.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
timestamp.h Fix and simplify some usages of TimestampDifference(). 2020-11-10 22:51:55 -05:00
tuplesort.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tuplestore.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
typcache.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
tzparser.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
uuid.h Update copyright for 2019 2019-01-02 12:44:25 -05:00
varbit.h Fix failure to zero-pad the result of bitshiftright(). 2019-09-22 17:46:00 -04:00
varlena.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
xml.h Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00