From 92e1583b439ffab1d20419998895932e4fbe32fd Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 30 Apr 2018 13:49:20 -0400 Subject: [PATCH] Don't do logical replication of TRUNCATE of zero tables When due to publication configuration, a TRUNCATE change ends up with zero tables to be published, don't send the message out, just skip it. It's not wrong, but obviously useless overhead. --- src/backend/replication/pgoutput/pgoutput.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index a3e5300679..86e0951a70 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -407,13 +407,16 @@ pgoutput_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, maybe_send_schema(ctx, relation, relentry); } - OutputPluginPrepareWrite(ctx, true); - logicalrep_write_truncate(ctx->out, - nrelids, - relids, - change->data.truncate.cascade, - change->data.truncate.restart_seqs); - OutputPluginWrite(ctx, true); + if (nrelids > 0) + { + OutputPluginPrepareWrite(ctx, true); + logicalrep_write_truncate(ctx->out, + nrelids, + relids, + change->data.truncate.cascade, + change->data.truncate.restart_seqs); + OutputPluginWrite(ctx, true); + } MemoryContextSwitchTo(old); MemoryContextReset(data->context); -- 2.40.0