aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/replication/logical/relation.c13
-rw-r--r--src/backend/replication/logical/worker.c48
-rw-r--r--src/backend/replication/pgoutput/pgoutput.c7
3 files changed, 42 insertions, 26 deletions
diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c
index e861c0ff802..4930f2ca348 100644
--- a/src/backend/replication/logical/relation.c
+++ b/src/backend/replication/logical/relation.c
@@ -620,7 +620,9 @@ logicalrep_partmap_init(void)
* logicalrep_partition_open
*
* Returned entry reuses most of the values of the root table's entry, save
- * the attribute map, which can be different for the partition.
+ * the attribute map, which can be different for the partition. However,
+ * we must physically copy all the data, in case the root table's entry
+ * gets freed/rebuilt.
*
* Note there's no logicalrep_partition_close, because the caller closes the
* component relation.
@@ -656,7 +658,7 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
part_entry->partoid = partOid;
- /* Remote relation is used as-is from the root entry. */
+ /* Remote relation is copied as-is from the root entry. */
entry = &part_entry->relmapentry;
entry->remoterel.remoteid = remoterel->remoteid;
entry->remoterel.nspname = pstrdup(remoterel->nspname);
@@ -699,7 +701,12 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root,
}
}
else
- entry->attrmap = attrmap;
+ {
+ /* Lacking copy_attmap, do this the hard way. */
+ entry->attrmap = make_attrmap(attrmap->maplen);
+ memcpy(entry->attrmap->attnums, attrmap->attnums,
+ attrmap->maplen * sizeof(AttrNumber));
+ }
entry->updatable = root->updatable;
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 98c26002e83..689a66cc72d 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -1477,12 +1477,13 @@ apply_handle_update_internal(ApplyExecutionData *edata,
else
{
/*
- * The tuple to be updated could not be found.
+ * The tuple to be updated could not be found. Do nothing except for
+ * emitting a log message.
*
- * TODO what to do here, change the log level to LOG perhaps?
+ * XXX should this be promoted to ereport(LOG) perhaps?
*/
elog(DEBUG1,
- "logical replication did not find row for update "
+ "logical replication did not find row to be updated "
"in replication target relation \"%s\"",
RelationGetRelationName(localrel));
}
@@ -1589,9 +1590,14 @@ apply_handle_delete_internal(ApplyExecutionData *edata,
}
else
{
- /* The tuple to be deleted could not be found. */
+ /*
+ * The tuple to be deleted could not be found. Do nothing except for
+ * emitting a log message.
+ *
+ * XXX should this be promoted to ereport(LOG) perhaps?
+ */
elog(DEBUG1,
- "logical replication did not find row for delete "
+ "logical replication did not find row to be deleted "
"in replication target relation \"%s\"",
RelationGetRelationName(localrel));
}
@@ -1728,31 +1734,31 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
found = FindReplTupleInLocalRel(estate, partrel,
&part_entry->remoterel,
remoteslot_part, &localslot);
-
- oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
- if (found)
- {
- /* Apply the update. */
- slot_modify_data(remoteslot_part, localslot,
- part_entry,
- newtup);
- MemoryContextSwitchTo(oldctx);
- }
- else
+ if (!found)
{
/*
- * The tuple to be updated could not be found.
+ * The tuple to be updated could not be found. Do nothing
+ * except for emitting a log message.
*
- * TODO what to do here, change the log level to LOG
- * perhaps?
+ * XXX should this be promoted to ereport(LOG) perhaps?
*/
elog(DEBUG1,
- "logical replication did not find row for update "
- "in replication target relation \"%s\"",
+ "logical replication did not find row to be updated "
+ "in replication target relation's partition \"%s\"",
RelationGetRelationName(partrel));
+ return;
}
/*
+ * Apply the update to the local tuple, putting the result in
+ * remoteslot_part.
+ */
+ oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
+ slot_modify_data(remoteslot_part, localslot, part_entry,
+ newtup);
+ MemoryContextSwitchTo(oldctx);
+
+ /*
* Does the updated tuple still satisfy the current
* partition's constraint?
*/
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index fe12d08a946..63f108f960f 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -612,8 +612,11 @@ pgoutput_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
/* Convert tuples if needed. */
if (relentry->map)
{
- oldtuple = execute_attr_map_tuple(oldtuple, relentry->map);
- newtuple = execute_attr_map_tuple(newtuple, relentry->map);
+ if (oldtuple)
+ oldtuple = execute_attr_map_tuple(oldtuple,
+ relentry->map);
+ newtuple = execute_attr_map_tuple(newtuple,
+ relentry->map);
}
}