aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/logical/decode.c10
-rw-r--r--src/backend/replication/logical/reorderbuffer.c9
-rw-r--r--src/include/replication/reorderbuffer.h4
3 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c
index 00b5b838d7c..1734ec96599 100644
--- a/src/backend/replication/logical/decode.c
+++ b/src/backend/replication/logical/decode.c
@@ -608,6 +608,8 @@ DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
change->data.tp.newtuple);
}
+ change->data.tp.clear_toast_afterwards = true;
+
ReorderBufferQueueChange(ctx->reorder, r->xl_xid, buf->origptr, change);
}
@@ -673,6 +675,8 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
#endif
}
+ change->data.tp.clear_toast_afterwards = true;
+
ReorderBufferQueueChange(ctx->reorder, r->xl_xid, buf->origptr, change);
}
@@ -710,6 +714,9 @@ DecodeDelete(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
r->xl_len - SizeOfHeapDelete,
change->data.tp.oldtuple);
}
+
+ change->data.tp.clear_toast_afterwards = true;
+
ReorderBufferQueueChange(ctx->reorder, r->xl_xid, buf->origptr, change);
}
@@ -795,6 +802,9 @@ DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
tuple->header.t_hoff = xlhdr->t_hoff;
}
+ /* reset toast reassembly only after the last chunk */
+ change->data.tp.clear_toast_afterwards = (i + 1) == xlrec->ntuples;
+
ReorderBufferQueueChange(ctx->reorder, r->xl_xid,
buf->origptr, change);
}
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 3f5c241d95a..2b0929cb78b 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -1383,7 +1383,14 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
{
ReorderBufferToastReplace(rb, txn, relation, change);
rb->apply_change(rb, txn, relation, change);
- ReorderBufferToastReset(rb, txn);
+
+ /*
+ * Only clear reassembled toast chunks if we're
+ * sure they're not required anymore. The creator
+ * of the tuple tells us.
+ */
+ if (change->data.tp.clear_toast_afterwards)
+ ReorderBufferToastReset(rb, txn);
}
/* we're not interested in toast deletions */
else if (change->action == REORDER_BUFFER_CHANGE_INSERT)
diff --git a/src/include/replication/reorderbuffer.h b/src/include/replication/reorderbuffer.h
index eaea5884efa..7ce0a4221f6 100644
--- a/src/include/replication/reorderbuffer.h
+++ b/src/include/replication/reorderbuffer.h
@@ -75,6 +75,10 @@ typedef struct ReorderBufferChange
{
/* relation that has been changed */
RelFileNode relnode;
+
+ /* no previously reassembled toast chunks are necessary anymore */
+ bool clear_toast_afterwards;
+
/* valid for DELETE || UPDATE */
ReorderBufferTupleBuf *oldtuple;
/* valid for INSERT || UPDATE */