aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2020-01-06 08:21:14 +0100
committerPeter Eisentraut <peter@eisentraut.org>2020-01-06 11:38:24 +0100
commit7474393e0b98971c7779cbb23c2d7d17e38a944c (patch)
tree23a234c861fede753db7b66b63122fe9239a8e41 /src/backend
parenta8474d863074cc97f49702b4cff4c69613f30b96 (diff)
downloadpostgresql-7474393e0b98971c7779cbb23c2d7d17e38a944c.tar.gz
postgresql-7474393e0b98971c7779cbb23c2d7d17e38a944c.zip
Have logical replication subscriber fire column triggers
The logical replication apply worker did not fire per-column update triggers because the updatedCols bitmap in the RTE was not populated. This fixes that. Reviewed-by: Euler Taveira <euler@timbira.com.br> Discussion: https://www.postgresql.org/message-id/flat/21673e2d-597c-6afe-637e-e8b10425b240%402ndquadrant.com
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/replication/logical/worker.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 2bd61d9d201..32437202fe5 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -27,6 +27,7 @@
#include "pgstat.h"
#include "funcapi.h"
+#include "access/sysattr.h"
#include "access/xact.h"
#include "access/xlog_internal.h"
@@ -706,6 +707,8 @@ apply_handle_update(StringInfo s)
bool has_oldtup;
TupleTableSlot *localslot;
TupleTableSlot *remoteslot;
+ RangeTblEntry *target_rte;
+ int i;
bool found;
MemoryContext oldctx;
@@ -735,6 +738,21 @@ apply_handle_update(StringInfo s)
RelationGetDescr(rel->localrel));
EvalPlanQualInit(&epqstate, estate, NULL, NIL, -1);
+ /*
+ * Populate updatedCols so that per-column triggers can fire. This could
+ * include more columns than were actually changed on the publisher
+ * because the logical replication protocol doesn't contain that
+ * information. But it would for example exclude columns that only exist
+ * on the subscriber, since we are not touching those.
+ */
+ target_rte = list_nth(estate->es_range_table, 0);
+ for (i = 0; i < remoteslot->tts_tupleDescriptor->natts; i++)
+ {
+ if (newtup.changed[i])
+ target_rte->updatedCols = bms_add_member(target_rte->updatedCols,
+ i + 1 - FirstLowInvalidHeapAttributeNumber);
+ }
+
PushActiveSnapshot(GetTransactionSnapshot());
ExecOpenIndices(estate->es_result_relation_info, false);