aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/worker.c
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 10:43:55 +0100
commit8c2bfd9f9b5da06a60ef7d46565bff2eaf5ceb2c (patch)
tree4d08308aaf46639fe05b32471e5648fd9067ab09 /src/backend/replication/logical/worker.c
parent6c1860b4d32082c411dd012bda4dfde35c41e942 (diff)
downloadpostgresql-8c2bfd9f9b5da06a60ef7d46565bff2eaf5ceb2c.tar.gz
postgresql-8c2bfd9f9b5da06a60ef7d46565bff2eaf5ceb2c.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/replication/logical/worker.c')
-rw-r--r--src/backend/replication/logical/worker.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 1dd9207ef03..a0384126399 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -690,6 +690,7 @@ apply_handle_update(StringInfo s)
bool has_oldtup;
TupleTableSlot *localslot;
TupleTableSlot *remoteslot;
+ RangeTblEntry *target_rte;
bool found;
MemoryContext oldctx;
@@ -720,6 +721,21 @@ apply_handle_update(StringInfo s)
&estate->es_tupleTable);
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 (int 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);