Re: Possible copy and past error? (\usr\backend\commands\analyze.c) - Mailing list pgsql-hackers

From Ranier Vilela
Subject Re: Possible copy and past error? (\usr\backend\commands\analyze.c)
Date
Msg-id CAEudQApFhMhCEWU4A9ZgTDF-Wek24L34StBMimxa-vgpgPY5Ew@mail.gmail.com
Whole thread Raw
In response to Re: Possible copy and past error? (\usr\backend\commands\analyze.c)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Possible copy and past error? (\usr\backend\commands\analyze.c)
Re: Possible copy and past error? (\usr\backend\commands\analyze.c)
List pgsql-hackers
Em sex., 27 de mar. de 2020 às 20:49, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
Ranier Vilela <ranier.vf@gmail.com> writes:
> Can someone check if there is a copy and paste error, at file:
> \usr\backend\commands\analyze.c, at lines 2225 and 2226?
> int num_mcv = stats->attr->attstattarget;
> int num_bins = stats->attr->attstattarget;

No, that's intentional I believe.  Those are independent variables
that just happen to start out with the same value.
Neither you nor I can say with 100% certainty that the original author's intention.

> If they really are the same values, it could be changed to:

> int num_mcv = stats->attr->attstattarget;
> int num_bins = num_mcv;

That would make it look like they are interdependent, which they are not.

That's exactly why, instead of proposing a patch, I asked a question.
 
> To silence this alert.

If you have a tool that complains about that coding, I think the
tool needs a solid whack upside the head.  There's nothing wrong
with the code, and it clearly expresses the intent, which the other
way doesn't.  (Or in other words: it's the compiler's job to
optimize away the duplicate fetch.  Not the programmer's.)
I completely disagree. My tools have proven their worth, including finding serious errors in the code, which fortunately have been fixed by other committers.
When issuing this alert, the tool does not value judgment regarding performance or optimization, but it does an excellent job of finding similar patterns in adjacent lines, and the only thing it asked for was to be asked if this was really the case. original author's intention.

regards,
Ranier Vilela

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: WAL usage calculation patch
Next
From: Sergei Kornilov
Date:
Subject: Re: allow online change primary_conninfo