Thread

Commits

  1. Move variable increment to the end of the loop

  1. code cleanups

    Justin Pryzby <pryzby@telsasoft.com> — 2022-11-23T17:24:36Z

    Some modest cleanups I've accumulated.
    
  2. Re: code cleanups

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-11-23T17:52:57Z

    Justin Pryzby <pryzby@telsasoft.com> writes:
    > Some modest cleanups I've accumulated.
    
    Hmm ...
    
    I don't especially care for either 0001 or 0002, mainly because
    I do not agree that this is good style:
    
    -	bool		nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS];
    +	bool		nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS] = {0};
    
    It causes the code to be far more in bed than I like with the assumption
    that we're initializing to physical zeroes.  The explicit loop method
    can be trivially adjusted to initialize to "true" or some other value;
    at least for bool arrays, that's true of memset'ing as well.  But this,
    if you decide you need something other than zeroes, is a foot-gun.
    In particular, someone whose C is a bit weak might mistakenly think that
    
    	bool		nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS] = {true};
    
    will set all the array elements to true.  Nor is there a plausible
    argument that this is more efficient.  So I don't care for this approach
    and I don't want to adopt it.
    
    0003: I agree with getting rid of the duplicated code, but did you go
    far enough?  Isn't the code just above those parent checks also pretty
    redundant?  It would be more intellectually consistent to move the full
    responsibility for setting acl_ok into a subroutine.  This shows in
    the patch as you have it because the header comment for
    recheck_parent_acl is completely out-of-context.
    
    0004: Right, somebody injected code in a poorly chosen place
    (yet another victim of the "add at the end" anti-pattern).
    
    0005: No particular objection, but it's not much of an improvement
    either.  It seems maybe a shade less consistent with the following
    line.
    
    0006: These changes will cause fetching of one more source byte than
    was fetched before.  I'm not sure that's safe, so I don't think this
    is an improvement.
    
    			regards, tom lane
    
    
    
    
  3. Re: code cleanups

    Robert Haas <robertmhaas@gmail.com> — 2022-11-23T18:05:54Z

    On Wed, Nov 23, 2022 at 12:53 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    > at least for bool arrays, that's true of memset'ing as well.  But this,
    > if you decide you need something other than zeroes, is a foot-gun.
    > In particular, someone whose C is a bit weak might mistakenly think that
    >
    >         bool            nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS] = {true};
    >
    > will set all the array elements to true.  Nor is there a plausible
    > argument that this is more efficient.  So I don't care for this approach
    > and I don't want to adopt it.
    
    I don't really know what the argument is for the explicit initializer
    style, but I think this argument against it is pretty weak.
    
    It should be more than fine to assume that anyone who is hacking on
    PostgreSQL is proficient in C. It's true that there might be some
    people who aren't, or who aren't familiar with the limitations of the
    initializer construct, and I include myself in that latter category. I
    don't think it was part of C when I learned C. But if we don't possess
    the collective expertise as a project to bring people who have missed
    these details of the C programming language up to speed, we should
    just throw in the towel now and go home.
    
    Hacking on PostgreSQL is HARD and it relies on knowing FAR more than
    just the basics of how to code in C. Put differently, if you can't
    even figure out how C works, you have no chance of doing anything very
    interesting with the PostgreSQL code base, because you're going to
    have to figure out a lot more than the basics of the implementation
    language to make a meaningful contribution.
    
    -- 
    Robert Haas
    EDB: http://www.enterprisedb.com
    
    
    
    
  4. Re: code cleanups

    John Naylor <john.naylor@enterprisedb.com> — 2022-12-20T07:20:20Z

    On Thu, Nov 24, 2022 at 12:53 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >
    > Justin Pryzby <pryzby@telsasoft.com> writes:
    > > Some modest cleanups I've accumulated.
    
    > 0004: Right, somebody injected code in a poorly chosen place
    > (yet another victim of the "add at the end" anti-pattern).
    
    I've pushed 0004.
    
    --
    John Naylor
    EDB: http://www.enterprisedb.com