From 4c3b45ea7b027bf734bbf113d41de0a100dda49a Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Thu, 26 Mar 2020 14:12:17 +0500 Subject: [PATCH v22 1/6] Keep track of writing on non-temporary relation --- src/backend/executor/nodeModifyTable.c | 16 ++++++++++++++++ src/include/access/xact.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 20a4c474cc..1ec07bad07 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -581,6 +581,10 @@ ExecInsert(ModifyTableState *mtstate, NULL, specToken); + /* Make note that we've wrote on non-temporary relation */ + if (RelationNeedsWAL(resultRelationDesc)) + MyXactFlags |= XACT_FLAGS_WROTENONTEMPREL; + /* insert index entries for tuple */ recheckIndexes = ExecInsertIndexTuples(slot, estate, true, &specConflict, @@ -619,6 +623,10 @@ ExecInsert(ModifyTableState *mtstate, estate->es_output_cid, 0, NULL); + /* Make note that we've wrote on non-temporary relation */ + if (RelationNeedsWAL(resultRelationDesc)) + MyXactFlags |= XACT_FLAGS_WROTENONTEMPREL; + /* insert index entries for tuple */ if (resultRelInfo->ri_NumIndices > 0) recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL, @@ -970,6 +978,10 @@ ldelete:; if (tupleDeleted) *tupleDeleted = true; + /* Make note that we've wrote on non-temporary relation */ + if (RelationNeedsWAL(resultRelationDesc)) + MyXactFlags |= XACT_FLAGS_WROTENONTEMPREL; + /* * If this delete is the result of a partition key update that moved the * tuple to a new partition, put this row into the transition OLD TABLE, @@ -1482,6 +1494,10 @@ lreplace:; if (canSetTag) (estate->es_processed)++; + /* Make note that we've wrote on non-temporary relation */ + if (RelationNeedsWAL(resultRelationDesc)) + MyXactFlags |= XACT_FLAGS_WROTENONTEMPREL; + /* AFTER ROW UPDATE Triggers */ ExecARUpdateTriggers(estate, resultRelInfo, tupleid, oldtuple, slot, recheckIndexes, diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 7ee04babc2..a04fc70326 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -102,6 +102,12 @@ extern int MyXactFlags; */ #define XACT_FLAGS_ACQUIREDACCESSEXCLUSIVELOCK (1U << 1) +/* + * XACT_FLAGS_WROTENONTEMPREL - set when we wrote data on non-temporary + * relation. + */ +#define XACT_FLAGS_WROTENONTEMPREL (1U << 2) + /* * start- and end-of-transaction callbacks for dynamically loaded modules */ -- 2.23.0