aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2024-09-24 15:25:18 -0700
committerNoah Misch <noah@leadboat.com>2024-09-24 15:25:18 -0700
commitaac2c9b4fde889d13f859c233c2523345e72d32b (patch)
tree65d5e1b73059d4c423dee459bcf58bc0c47b8a9a /src/backend/executor/execMain.c
parenta07e03fd8fa7daf4d1356f7cb501ffe784ea6257 (diff)
downloadpostgresql-aac2c9b4fde889d13f859c233c2523345e72d32b.tar.gz
postgresql-aac2c9b4fde889d13f859c233c2523345e72d32b.zip
For inplace update durability, make heap_update() callers wait.
The previous commit fixed some ways of losing an inplace update. It remained possible to lose one when a backend working toward a heap_update() copied a tuple into memory just before inplace update of that tuple. In catalogs eligible for inplace update, use LOCKTAG_TUPLE to govern admission to the steps of copying an old tuple, modifying it, and issuing heap_update(). This includes MERGE commands. To avoid changing most of the pg_class DDL, don't require LOCKTAG_TUPLE when holding a relation lock sufficient to exclude inplace updaters. Back-patch to v12 (all supported versions). In v13 and v12, "UPDATE pg_class" or "UPDATE pg_database" can still lose an inplace update. The v14+ UPDATE fix needs commit 86dc90056dfdbd9d1b891718d2e5614e3e432f35, and it wasn't worth reimplementing that fix without such infrastructure. Reviewed by Nitin Motiani and (in earlier versions) Heikki Linnakangas. Discussion: https://postgr.es/m/20231027214946.79.nmisch@google.com
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 713cf3e802c..728cdee480b 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1036,6 +1036,10 @@ CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
Relation resultRel = resultRelInfo->ri_RelationDesc;
FdwRoutine *fdwroutine;
+ /* Expect a fully-formed ResultRelInfo from InitResultRelInfo(). */
+ Assert(resultRelInfo->ri_needLockTagTuple ==
+ IsInplaceUpdateRelation(resultRel));
+
switch (resultRel->rd_rel->relkind)
{
case RELKIND_RELATION:
@@ -1216,6 +1220,8 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
resultRelInfo->ri_NumIndices = 0;
resultRelInfo->ri_IndexRelationDescs = NULL;
resultRelInfo->ri_IndexRelationInfo = NULL;
+ resultRelInfo->ri_needLockTagTuple =
+ IsInplaceUpdateRelation(resultRelationDesc);
/* make a copy so as not to depend on relcache info not changing... */
resultRelInfo->ri_TrigDesc = CopyTriggerDesc(resultRelationDesc->trigdesc);
if (resultRelInfo->ri_TrigDesc)