test_decoding: Add comments about delaying BEGIN/PREPARE
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 23 Mar 2022 15:17:00 +0000 (16:17 +0100)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 23 Mar 2022 15:46:57 +0000 (16:46 +0100)
It is not immediately obvious why we return early in these functions;
these comments should make it so.

Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: https://postgr.es/m/202202141336.xv35beswc6ec@alvherre.pgsql

contrib/test_decoding/test_decoding.c

index ea22649e41d2157b554c9992170ea2e829faa733..c7a87f5fe5b2ef2529ba122b98ee31a06439acc0 100644 (file)
@@ -322,6 +322,10 @@ pg_decode_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
    txndata->xact_wrote_changes = false;
    txn->output_plugin_private = txndata;
 
+   /*
+    * If asked to skip empty transactions, we'll emit BEGIN at the point where
+    * the first operation is received for this transaction.
+    */
    if (data->skip_empty_xacts)
        return;
 
@@ -378,6 +382,10 @@ pg_decode_begin_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
    txndata->xact_wrote_changes = false;
    txn->output_plugin_private = txndata;
 
+   /*
+    * If asked to skip empty transactions, we'll emit BEGIN at the point where
+    * the first operation is received for this transaction.
+    */
    if (data->skip_empty_xacts)
        return;
 
@@ -392,6 +400,10 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
    TestDecodingData *data = ctx->output_plugin_private;
    TestDecodingTxnData *txndata = txn->output_plugin_private;
 
+   /*
+    * If asked to skip empty transactions, we'll emit PREPARE at the point
+    * where the first operation is received for this transaction.
+    */
    if (data->skip_empty_xacts && !txndata->xact_wrote_changes)
        return;