diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2020-01-06 08:21:14 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2020-01-06 11:38:33 +0100 |
commit | 66fd0adc73a8d3b0c43423c7d263cba37edaa36b (patch) | |
tree | 3c7cfae722750cc0965e42265975f02d5ba41c9d /src/backend/replication/logical/worker.c | |
parent | 91595d181707e1ebfb37f7334ad89f24f677c8a7 (diff) |
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.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 67126088385..7e3f3f0b0c0 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" @@ -703,6 +704,8 @@ apply_handle_update(StringInfo s) bool has_oldtup; TupleTableSlot *localslot; TupleTableSlot *remoteslot; + RangeTblEntry *target_rte; + int i; bool found; MemoryContext oldctx; @@ -732,6 +735,21 @@ apply_handle_update(StringInfo s) ExecSetSlotDescriptor(localslot, 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); |