Don't do logical replication of TRUNCATE of zero tables
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 30 Apr 2018 17:49:20 +0000 (13:49 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 30 Apr 2018 17:49:20 +0000 (13:49 -0400)
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

index a3e5300679f896adb05e5d518a84d6ee675c6c80..86e0951a700e1c3737c6098cc5bc5e143505db4d 100644 (file)
@@ -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);