Re: Yet another small patch - reorderbuffer.c:1099 - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Yet another small patch - reorderbuffer.c:1099
Date
Msg-id 20160405143827.GA258373@alvherre.pgsql
Whole thread Raw
In response to Re: Yet another small patch - reorderbuffer.c:1099  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: Yet another small patch - reorderbuffer.c:1099  (Robert Haas <robertmhaas@gmail.com>)
Re: Yet another small patch - reorderbuffer.c:1099  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Simon Riggs wrote:
> On 5 April 2016 at 10:12, Andres Freund <andres@anarazel.de> wrote:
> 
> > On 2016-04-05 12:07:40 +0300, Aleksander Alekseev wrote:
> > > > I recall discussing this code with Andres, and I think that he has
> > > > mentioned me this is intentional, because should things be changed for
> > > > a reason or another in the future, we want to keep in mind that a list
> > > > of TXIDs and a list of sub-TXIDs should be handled differently.
> > >
> > > I see. If this it true I think there should be a comment that explains
> > > it. When you read such a code you suspect a bug. Not mentioning that
> > > static code analyzers (I'm currently experimenting with Clang and PVS
> > > Studio) complain about code like this.
> >
> > There's different comments in both branches...
> 
> Then one or both of the comments is incomplete.

IMO the code is wrong.  There should be a single block comment saying
something like "Remove the node from its containing list.  In the FOO
case, the list corresponds to BAR and therefore we delete it because
BAZ.  In the QUUX case the list is PLUGH and we delete in because THUD."
Then a single line dlist_delete(...) follows.

The current arrangement looks bizantine to me, for no reason.  If we
think that one of the two branches might do something additional to the
list deletion, surely that will be in a separate stanza with its own
comment; and if we ever want to remove the list deletion from one of the
two cases (something that strikes me as unlikely) then we will need to
fix the comment, too.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: Move PinBuffer and UnpinBuffer to atomics
Next
From: Robert Haas
Date:
Subject: Re: oversight in parallel aggregate