From 7b8bad2a26a0d5b02b10a1540b4de2c32fdc2047 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Thu, 5 Dec 2019 16:59:47 +0900 Subject: [PATCH v18 1/5] Keep track of writing on non-temporary relation Authors: Masahiko Sawada, Ahutosh Bapat --- 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 d71c0a4322..870a7428f1 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -574,6 +574,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, @@ -612,6 +616,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, @@ -963,6 +971,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, @@ -1475,6 +1487,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