On Tue, Mar 14, 2023 at 10:33 PM vignesh C <vignes...@gmail.com> wrote: > > On Tue, 14 Mar 2023 at 12:37, Peter Smith <smithpb2...@gmail.com> wrote: > > > > Thanks for the review! > > > > On Mon, Mar 13, 2023 at 6:19 PM vignesh C <vignes...@gmail.com> wrote: > > ... > > > Few comments: > > > 1) Can we move the macros along with the other macros present in this > > > file, just above this structure, similar to the macros added for > > > txn_flags: > > > /* Toplevel transaction for this subxact (NULL for top-level). */ > > > +#define isa_toptxn(rbtxn) (rbtxn->toptxn == NULL) > > > +#define isa_subtxn(rbtxn) (rbtxn->toptxn != NULL) > > > +#define get_toptxn(rbtxn) (isa_subtxn(rbtxn) ? rbtxn->toptxn : rbtxn) > > > > > > 2) The macro name can be changed to rbtxn_is_toptxn, rbtxn_is_subtxn > > > and rbtxn_get_toptxn to keep it consistent with others: > > > /* Toplevel transaction for this subxact (NULL for top-level). */ > > > +#define isa_toptxn(rbtxn) (rbtxn->toptxn == NULL) > > > +#define isa_subtxn(rbtxn) (rbtxn->toptxn != NULL) > > > +#define get_toptxn(rbtxn) (isa_subtxn(rbtxn) ? rbtxn->toptxn : rbtxn) > > > > > > 3) We could add separate comments for each of the macros: > > > /* Toplevel transaction for this subxact (NULL for top-level). */ > > > +#define isa_toptxn(rbtxn) (rbtxn->toptxn == NULL) > > > +#define isa_subtxn(rbtxn) (rbtxn->toptxn != NULL) > > > +#define get_toptxn(rbtxn) (isa_subtxn(rbtxn) ? rbtxn->toptxn : rbtxn) > > > > > > > All the above are fixed as suggested. > > > > > 4) We check if txn->toptxn is not null twice here both in if condition > > > and in the assignment, we could retain the assignment operation as > > > earlier to remove the 2nd check: > > > - if (txn->toptxn) > > > - txn = txn->toptxn; > > > + if (isa_subtxn(txn)) > > > + txn = get_toptxn(txn); > > > > > > We could avoid one check again by: > > > + if (isa_subtxn(txn)) > > > + txn = txn->toptxn; > > > > > > > Yeah, that is true, but I chose not to keep the original assignment in > > this case mainly because then it is consistent with the other changed > > code --- e.g. Every other direct member assignment/access of the > > 'toptxn' member now hides behind the macros so I did not want this > > single place to be the odd one out. TBH, I don't think 1 extra check > > is of any significance, but it is not a problem to change like you > > suggested if other people also want it done that way. > > The same issue exists here too: > 1) > - if (toptxn != NULL && !rbtxn_has_catalog_changes(toptxn)) > + if (rbtxn_is_subtxn(txn)) > { > - toptxn->txn_flags |= RBTXN_HAS_CATALOG_CHANGES; > - dclist_push_tail(&rb->catchange_txns, > &toptxn->catchange_node); > + ReorderBufferTXN *toptxn = rbtxn_get_toptxn(txn); > > 2) > - if (change->txn->toptxn) > - topxid = change->txn->toptxn->xid; > + if (rbtxn_is_subtxn(change->txn)) > + topxid = rbtxn_get_toptxn(change->txn)->xid; > > If you plan to fix, bothe the above also should be handled.
OK, noted. Anyway, for now, I preferred the 'toptxn' member to be consistently hidden in the code so I don't plan to remove those macros. Also, please see Amit's reply [1] to your suggestion. > > 3) The comment on top of rbtxn_get_toptxn could be kept similar in > both the below places. I know it is not because of your change, but > since it is a very small change probably we could include it along > with this patch: > @@ -717,10 +717,7 @@ ReorderBufferProcessPartialChange(ReorderBuffer > *rb, ReorderBufferTXN *txn, > return; > > /* Get the top transaction. */ > - if (txn->toptxn != NULL) > - toptxn = txn->toptxn; > - else > - toptxn = txn; > + toptxn = rbtxn_get_toptxn(txn); > > /* > * Indicate a partial change for toast inserts. The change will be > @@ -812,10 +809,7 @@ ReorderBufferQueueChange(ReorderBuffer *rb, > TransactionId xid, XLogRecPtr lsn, > ReorderBufferTXN *toptxn; > > /* get the top transaction */ > - if (txn->toptxn != NULL) > - toptxn = txn->toptxn; > - else > - toptxn = txn; > + toptxn = rbtxn_get_toptxn(txn); > IMO the comment ("/* get the top transaction */") was not really saying anything useful that is not already obvious from the macro name ("rbtxn_get_toptxn"). So I've removed it entirely in your 2nd case. This change is consistent with other parts of the patch where the toptxn is just assigned in the declaration. PSA v3. [2] ------ [1] Amit reply to your suggestion - https://www.postgresql.org/message-id/CAA4eK1%2BoqfUSC3vpu6bJzgfnSmu_yaeoLS%3DRb3416GuS5iRP1Q%40mail.gmail.com [2] v3 - https://www.postgresql.org/message-id/CAHut%2BPtrD4xU4OPUB64ZK%2BDPDhfKn3zph%3DnDpEWUFFzUvMKo2w%40mail.gmail.com Kind Regards, Peter Smith. Fujitsu Australia