Make some use of anonymous unions [reorderbuffer xact_time]
authorPeter Eisentraut <[email protected]>
Tue, 30 Sep 2025 10:24:15 +0000 (12:24 +0200)
committerPeter Eisentraut <[email protected]>
Tue, 30 Sep 2025 10:35:50 +0000 (12:35 +0200)
Make some use of anonymous unions, which are allowed as of C11, as
examples and encouragement for future code, and to test compilers.

This commit changes the ReorderBufferTXN struct.

Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/f00a9968-388e-4f8c-b5ef-5102e962d997%40eisentraut.org

contrib/test_decoding/test_decoding.c
src/backend/replication/logical/proto.c
src/backend/replication/logical/reorderbuffer.c
src/backend/replication/pgoutput/pgoutput.c
src/include/replication/reorderbuffer.h

index f671a7d4b3125c56db7fba452d43fd3f500e3031..36e77c69e1c19471d42f3f61a054a67bda092cb4 100644 (file)
@@ -340,7 +340,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.commit_time));
+                        timestamptz_to_str(txn->commit_time));
 
    OutputPluginWrite(ctx, true);
 }
@@ -391,7 +391,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.prepare_time));
+                        timestamptz_to_str(txn->prepare_time));
 
    OutputPluginWrite(ctx, true);
 }
@@ -413,7 +413,7 @@ pg_decode_commit_prepared_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.commit_time));
+                        timestamptz_to_str(txn->commit_time));
 
    OutputPluginWrite(ctx, true);
 }
@@ -437,7 +437,7 @@ pg_decode_rollback_prepared_txn(LogicalDecodingContext *ctx,
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.commit_time));
+                        timestamptz_to_str(txn->commit_time));
 
    OutputPluginWrite(ctx, true);
 }
@@ -874,7 +874,7 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.prepare_time));
+                        timestamptz_to_str(txn->prepare_time));
 
    OutputPluginWrite(ctx, true);
 }
@@ -903,7 +903,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
 
    if (data->include_timestamp)
        appendStringInfo(ctx->out, " (at %s)",
-                        timestamptz_to_str(txn->xact_time.commit_time));
+                        timestamptz_to_str(txn->commit_time));
 
    OutputPluginWrite(ctx, true);
 }
index 1b3d9eb49dd7028105237566cbcb966ce71446c3..2436a263dc27a0426b5a1b82115d6c0c28115451 100644 (file)
@@ -52,7 +52,7 @@ logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn)
 
    /* fixed fields */
    pq_sendint64(out, txn->final_lsn);
-   pq_sendint64(out, txn->xact_time.commit_time);
+   pq_sendint64(out, txn->commit_time);
    pq_sendint32(out, txn->xid);
 }
 
@@ -88,7 +88,7 @@ logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn,
    /* send fields */
    pq_sendint64(out, commit_lsn);
    pq_sendint64(out, txn->end_lsn);
-   pq_sendint64(out, txn->xact_time.commit_time);
+   pq_sendint64(out, txn->commit_time);
 }
 
 /*
@@ -120,7 +120,7 @@ logicalrep_write_begin_prepare(StringInfo out, ReorderBufferTXN *txn)
    /* fixed fields */
    pq_sendint64(out, txn->final_lsn);
    pq_sendint64(out, txn->end_lsn);
-   pq_sendint64(out, txn->xact_time.prepare_time);
+   pq_sendint64(out, txn->prepare_time);
    pq_sendint32(out, txn->xid);
 
    /* send gid */
@@ -173,7 +173,7 @@ logicalrep_write_prepare_common(StringInfo out, LogicalRepMsgType type,
    /* send fields */
    pq_sendint64(out, prepare_lsn);
    pq_sendint64(out, txn->end_lsn);
-   pq_sendint64(out, txn->xact_time.prepare_time);
+   pq_sendint64(out, txn->prepare_time);
    pq_sendint32(out, txn->xid);
 
    /* send gid */
@@ -253,7 +253,7 @@ logicalrep_write_commit_prepared(StringInfo out, ReorderBufferTXN *txn,
    /* send fields */
    pq_sendint64(out, commit_lsn);
    pq_sendint64(out, txn->end_lsn);
-   pq_sendint64(out, txn->xact_time.commit_time);
+   pq_sendint64(out, txn->commit_time);
    pq_sendint32(out, txn->xid);
 
    /* send gid */
@@ -311,7 +311,7 @@ logicalrep_write_rollback_prepared(StringInfo out, ReorderBufferTXN *txn,
    pq_sendint64(out, prepare_end_lsn);
    pq_sendint64(out, txn->end_lsn);
    pq_sendint64(out, prepare_time);
-   pq_sendint64(out, txn->xact_time.commit_time);
+   pq_sendint64(out, txn->commit_time);
    pq_sendint32(out, txn->xid);
 
    /* send gid */
@@ -1119,7 +1119,7 @@ logicalrep_write_stream_commit(StringInfo out, ReorderBufferTXN *txn,
    /* send fields */
    pq_sendint64(out, commit_lsn);
    pq_sendint64(out, txn->end_lsn);
-   pq_sendint64(out, txn->xact_time.commit_time);
+   pq_sendint64(out, txn->commit_time);
 }
 
 /*
index 4736f993c374373e992fdcf395cfd68975371461..a5e165fb123c83cf39330587de02b7680ebeeafa 100644 (file)
@@ -2830,7 +2830,7 @@ ReorderBufferReplay(ReorderBufferTXN *txn,
 
    txn->final_lsn = commit_lsn;
    txn->end_lsn = end_lsn;
-   txn->xact_time.commit_time = commit_time;
+   txn->commit_time = commit_time;
    txn->origin_id = origin_id;
    txn->origin_lsn = origin_lsn;
 
@@ -2922,7 +2922,7 @@ ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
     */
    txn->final_lsn = prepare_lsn;
    txn->end_lsn = end_lsn;
-   txn->xact_time.prepare_time = prepare_time;
+   txn->prepare_time = prepare_time;
    txn->origin_id = origin_id;
    txn->origin_lsn = origin_lsn;
 
@@ -2979,7 +2979,7 @@ ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid,
    txn->gid = pstrdup(gid);
 
    ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
-                       txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
+                       txn->prepare_time, txn->origin_id, txn->origin_lsn);
 
    /*
     * Send a prepare if not already done so. This might occur if we have
@@ -3018,7 +3018,7 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
     * be later used for rollback.
     */
    prepare_end_lsn = txn->end_lsn;
-   prepare_time = txn->xact_time.prepare_time;
+   prepare_time = txn->prepare_time;
 
    /* add the gid in the txn */
    txn->gid = pstrdup(gid);
@@ -3050,12 +3050,12 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
         * prepared after the restart.
         */
        ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
-                           txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn);
+                           txn->prepare_time, txn->origin_id, txn->origin_lsn);
    }
 
    txn->final_lsn = commit_lsn;
    txn->end_lsn = end_lsn;
-   txn->xact_time.commit_time = commit_time;
+   txn->commit_time = commit_time;
    txn->origin_id = origin_id;
    txn->origin_lsn = origin_lsn;
 
@@ -3095,7 +3095,7 @@ ReorderBufferAbort(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn,
    if (txn == NULL)
        return;
 
-   txn->xact_time.abort_time = abort_time;
+   txn->abort_time = abort_time;
 
    /* For streamed transactions notify the remote node about the abort. */
    if (rbtxn_is_streamed(txn))
index 80540c017bd3aa5b66ebe1a7b674f2d2b8a7e067..92eb17049c3ce7203713d17b8c9f30041c1c5cb5 100644 (file)
@@ -1888,7 +1888,7 @@ pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
 
    OutputPluginPrepareWrite(ctx, true);
    logicalrep_write_stream_abort(ctx->out, toptxn->xid, txn->xid, abort_lsn,
-                                 txn->xact_time.abort_time, write_abort_info);
+                                 txn->abort_time, write_abort_info);
 
    OutputPluginWrite(ctx, true);
 
index fa0745552f86c69427759975e82e56a53e571bf2..91dc7e5e448d8fd1f7cac3c5adb659167dba5b91 100644 (file)
@@ -359,7 +359,7 @@ typedef struct ReorderBufferTXN
        TimestampTz commit_time;
        TimestampTz prepare_time;
        TimestampTz abort_time;
-   }           xact_time;
+   };
 
    /*
     * The base snapshot is used to decode all changes until either this