Re: Avoid unused value (src/fe_utils/print.c)

2023-07-28 Thread Karina Litskevich
On Tue, Jul 25, 2023 at 1:04 AM Ranier Vilela  wrote:

> Checked today, Coverity does not complain about need_recordsep.
>

Great! Thanks.
So v2 patch makes Coverity happy, and as for me doesn't make the code
less readable. Does anyone have any objections?

Best regards,
Karina Litskevich
Postgres Professional: http://postgrespro.com/


Re: Avoid unused value (src/fe_utils/print.c)

2023-07-24 Thread Ranier Vilela
Em sex., 21 de jul. de 2023 às 09:13, Karina Litskevich <
litskevichkar...@gmail.com> escreveu:

>
>
> On Wed, Jul 12, 2023 at 1:46 AM Ranier Vilela  wrote:
>
>>  As there is consensus to keep the no-op assignment,
>> I will go ahead and reject the patch.
>>
>
> In your patch you suggest removing two assignments, and we only have
> consensus to keep one of them. The other one is an obvious no-op.
>
> I attached a patch that removes only one assignment. Could you please try
> it and check whether Coverity is still complaining about need_recordsep
> variable?
>
Yeah.
Checked today, Coverity does not complain about need_recordsep.

best regards,
Ranier Vilela


Re: Avoid unused value (src/fe_utils/print.c)

2023-07-21 Thread Karina Litskevich
On Wed, Jul 12, 2023 at 1:46 AM Ranier Vilela  wrote:

>  As there is consensus to keep the no-op assignment,
> I will go ahead and reject the patch.
>

In your patch you suggest removing two assignments, and we only have
consensus to keep one of them. The other one is an obvious no-op.

I attached a patch that removes only one assignment. Could you please try
it and check whether Coverity is still complaining about need_recordsep
variable?

Best regards,
Karina Litskevich
Postgres Professional: http://postgrespro.com/
From 92c86657181c13c48a4b4176bf4ad1d6221cf9b5 Mon Sep 17 00:00:00 2001
From: Karina Litskevich 
Date: Fri, 21 Jul 2023 14:43:44 +0300
Subject: [PATCH v2] Avoid unused value in print.c

---
 src/fe_utils/print.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/fe_utils/print.c b/src/fe_utils/print.c
index 7af1ccb6b5..d10f33cd9f 100644
--- a/src/fe_utils/print.c
+++ b/src/fe_utils/print.c
@@ -484,10 +484,7 @@ print_unaligned_text(const printTableContent *cont, FILE *fout)
 			for (f = footers; f; f = f->next)
 			{
 if (need_recordsep)
-{
 	print_separator(cont->opt->recordSep, fout);
-	need_recordsep = false;
-}
 fputs(f->data, fout);
 need_recordsep = true;
 			}
-- 
2.34.1



Re: Avoid unused value (src/fe_utils/print.c)

2023-07-11 Thread Ranier Vilela
Em ter., 11 de jul. de 2023 às 19:34, Marko Tiikkaja 
escreveu:

> On Thu, Jul 6, 2023 at 5:37 PM Karina Litskevich
>  wrote:
> > My point is, technically right now you won't see any difference in output
> > if you remove the line. Because if we get to that line the need_recordsep
> > is already true. However, understanding why it is true is complicated.
> That's
> > why if you remove the line people who read the code will wonder why we
> don't
> > need a separator after "fputs"ing a footer. So keeping that line will
> make
> > the code more readable.
> > Moreover, removing the line will possibly complicate the future
> maintenance.
> > As I wrote in the part you just quoted, if the function changes in the
> way
> > that need_recordsep is not true right before printing footers any more,
> then
> > output will be unexpected.
>
> I agree with Karina here.  Either this patch should keep the
> "need_recordsep = true;" line, thus removing the no-op assignment to
> false and making the code slightly less unreadable; or the entire
> function should be refactored for readability.
>
 As there is consensus to keep the no-op assignment,
I will go ahead and reject the patch.

regards,
Ranier Vilela


Re: Avoid unused value (src/fe_utils/print.c)

2023-07-11 Thread Marko Tiikkaja
On Thu, Jul 6, 2023 at 5:37 PM Karina Litskevich
 wrote:
> My point is, technically right now you won't see any difference in output
> if you remove the line. Because if we get to that line the need_recordsep
> is already true. However, understanding why it is true is complicated. That's
> why if you remove the line people who read the code will wonder why we don't
> need a separator after "fputs"ing a footer. So keeping that line will make
> the code more readable.
> Moreover, removing the line will possibly complicate the future maintenance.
> As I wrote in the part you just quoted, if the function changes in the way
> that need_recordsep is not true right before printing footers any more, then
> output will be unexpected.

I agree with Karina here.  Either this patch should keep the
"need_recordsep = true;" line, thus removing the no-op assignment to
false and making the code slightly less unreadable; or the entire
function should be refactored for readability.


.m




Re: Avoid unused value (src/fe_utils/print.c)

2023-07-06 Thread Karina Litskevich
>
>
>
>> But
>> it's not obvious, so I also have doubts about removing this line. If
>> someday
>> print options are changed, for example to support printing footers and not
>> printing headers, or anything else changes in this function, the output
>> might
>> be unexpected with this line removed.
>
>
> That part I didn't understand.
> How are we going to make this function less readable by removing the
> complicating part.
>

My point is, technically right now you won't see any difference in output
if you remove the line. Because if we get to that line the need_recordsep
is already true. However, understanding why it is true is complicated.
That's
why if you remove the line people who read the code will wonder why we don't
need a separator after "fputs"ing a footer. So keeping that line will make
the code more readable.
Moreover, removing the line will possibly complicate the future maintenance.
As I wrote in the part you just quoted, if the function changes in the way
that need_recordsep is not true right before printing footers any more, then
output will be unexpected.

Best regards,
Karina Litskevich
Postgres Professional: http://postgrespro.com/


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-30 Thread Ranier Vilela
Em sex., 30 de jun. de 2023 às 13:00, Alexander Lakhin 
escreveu:

> Hello Karina,
>
> 30.06.2023 17:25, Karina Litskevich wrote:
> > Hi,
> >
> > Alexander wrote:
> >
> >> It also aligns the code with print_unaligned_vertical(), but I can't
> see why
> >> need_recordsep = true;
> >> is a no-op here (scan-build dislikes only need_recordsep = false;).
> >> I suspect that removing that line will change the behaviour in cases
> when
> >> need_recordsep = false after the loop "print cells" and the loop
> >> "for (footers)" is executed.
> > As I understand cont->cells is supoused to have all cont->ncolumns *
> cont->nrows
> > entries filled so the loop "print cells" always assigns need_recordsep =
> true,
> > except when there are no cells at all or cancel_pressed == true.
> > If cancel_pressed == true then footers are not printed. So to have
> > need_recordsep == false before the loop "for (footers)" table should be
> empty,
> > and need_recordsep should be false before the loop "print cells". It can
> only
> > be false there when cont->opt->start_table == true and opt_tuples_only
> == true
> > so that headers are not printed. But when opt_tuples_only == true
> footers are
> > not printed either.
> >
> > So technically removing "need_recordsep = true;" won't change the
> outcome. But
> > it's not obvious, so I also have doubts about removing this line. If
> someday
> > print options are changed, for example to support printing footers and
> not
> > printing headers, or anything else changes in this function, the output
> might
> > be unexpected with this line removed.
>
> Hi Alexander,


> I think that the question that should be answered before moving forward
> here is: what this discussion is expected to result in?
>
I hope to make the function more readable and maintainable.


> If the goal is to avoid an unused value to make Coverity/clang`s scan-build
> a little happier, then maybe just don't touch other line, that is not
> recognized as dead (at least by scan-build;



> I wonder what Coverity says
> about that line).
>
   if (cont->opt->stop_table)
477{
478printTableFooter *footers = footers_with_default(cont);
479
480if (!opt_tuples_only && footers != NULL && !
cancel_pressed)
481{
482printTableFooter *f;
483
484for (f = footers; f; f = f->next)
485{
486if (need_recordsep)
487{
488print_separator(cont->opt->
recordSep, fout);

CID 1512766 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value: Assigning
value false to need_recordsep here, but that stored value is overwritten
before it can be used.
489need_recordsep = false;
490}
491fputs(f->data, fout);

value_overwrite: Overwriting previous write to need_recordsep with value
true.
492need_recordsep = true;
493}
494}
495


> Otherwise, if the goal is to do review the code and make it cleaner, then
> why not get rid of "if (need_recordsep)" there?
>
I don't agree with removing this line, as it is essential to print the
separators, in the footers.

best regards,
Ranier Vilela


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-30 Thread Ranier Vilela
Em sex., 30 de jun. de 2023 às 11:26, Karina Litskevich <
litskevichkar...@gmail.com> escreveu:

> Hi,
>
> Alexander wrote:
>
> > It also aligns the code with print_unaligned_vertical(), but I can't see
> why
> > need_recordsep = true;
> > is a no-op here (scan-build dislikes only need_recordsep = false;).
> > I suspect that removing that line will change the behaviour in cases when
> > need_recordsep = false after the loop "print cells" and the loop
> > "for (footers)" is executed.
>
> Hi Karina,


> As I understand cont->cells is supoused to have all cont->ncolumns *
> cont->nrows
> entries filled so the loop "print cells" always assigns need_recordsep =
> true,
> except when there are no cells at all or cancel_pressed == true.
> If cancel_pressed == true then footers are not printed. So to have
> need_recordsep == false before the loop "for (footers)" table should be
> empty,
> and need_recordsep should be false before the loop "print cells". It can
> only
> be false there when cont->opt->start_table == true and opt_tuples_only ==
> true
> so that headers are not printed. But when opt_tuples_only == true footers
> are
> not printed either.
>
> So technically removing "need_recordsep = true;" won't change the outcome.

Thanks for the confirmation.


> But
> it's not obvious, so I also have doubts about removing this line. If
> someday
> print options are changed, for example to support printing footers and not
> printing headers, or anything else changes in this function, the output
> might
> be unexpected with this line removed.


That part I didn't understand.
How are we going to make this function less readable by removing the
complicating part.

best regards,
Ranier Vilela


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-30 Thread Alexander Lakhin

Hello Karina,

30.06.2023 17:25, Karina Litskevich wrote:

Hi,

Alexander wrote:


It also aligns the code with print_unaligned_vertical(), but I can't see why
need_recordsep = true;
is a no-op here (scan-build dislikes only need_recordsep = false;).
I suspect that removing that line will change the behaviour in cases when
need_recordsep = false after the loop "print cells" and the loop
"for (footers)" is executed.

As I understand cont->cells is supoused to have all cont->ncolumns * cont->nrows
entries filled so the loop "print cells" always assigns need_recordsep = true,
except when there are no cells at all or cancel_pressed == true.
If cancel_pressed == true then footers are not printed. So to have
need_recordsep == false before the loop "for (footers)" table should be empty,
and need_recordsep should be false before the loop "print cells". It can only
be false there when cont->opt->start_table == true and opt_tuples_only == true
so that headers are not printed. But when opt_tuples_only == true footers are
not printed either.

So technically removing "need_recordsep = true;" won't change the outcome. But
it's not obvious, so I also have doubts about removing this line. If someday
print options are changed, for example to support printing footers and not
printing headers, or anything else changes in this function, the output might
be unexpected with this line removed.


I think that the question that should be answered before moving forward
here is: what this discussion is expected to result in?
If the goal is to avoid an unused value to make Coverity/clang`s scan-build
a little happier, then maybe just don't touch other line, that is not
recognized as dead (at least by scan-build; I wonder what Coverity says
about that line).
Otherwise, if the goal is to do review the code and make it cleaner, then
why not get rid of "if (need_recordsep)" there?

Best regards,
Alexander




Re: Avoid unused value (src/fe_utils/print.c)

2023-06-30 Thread Karina Litskevich
Hi,

Alexander wrote:

> It also aligns the code with print_unaligned_vertical(), but I can't see why
> need_recordsep = true;
> is a no-op here (scan-build dislikes only need_recordsep = false;).
> I suspect that removing that line will change the behaviour in cases when
> need_recordsep = false after the loop "print cells" and the loop
> "for (footers)" is executed.

As I understand cont->cells is supoused to have all cont->ncolumns * cont->nrows
entries filled so the loop "print cells" always assigns need_recordsep = true,
except when there are no cells at all or cancel_pressed == true.
If cancel_pressed == true then footers are not printed. So to have
need_recordsep == false before the loop "for (footers)" table should be empty,
and need_recordsep should be false before the loop "print cells". It can only
be false there when cont->opt->start_table == true and opt_tuples_only == true
so that headers are not printed. But when opt_tuples_only == true footers are
not printed either.

So technically removing "need_recordsep = true;" won't change the outcome. But
it's not obvious, so I also have doubts about removing this line. If someday
print options are changed, for example to support printing footers and not
printing headers, or anything else changes in this function, the output might
be unexpected with this line removed.

Best regards,
Karina Litskevich
Postgres Professional: http://postgrespro.com/




Re: Avoid unused value (src/fe_utils/print.c)

2023-06-04 Thread Ranier Vilela
Em dom., 4 de jun. de 2023 às 01:00, Alexander Lakhin 
escreveu:

> Hi Michael,
>
> 04.06.2023 01:42, Michael Paquier wrote:
> > On Sat, Jun 03, 2023 at 03:00:01PM +0300, Alexander Lakhin wrote:
> >> Clang' scan-build detects 58 errors "Dead assignment", including that
> one.
> >> Maybe it would be more sensible to eliminate all errors of this class?
> > Depends on if this makes any code changed a bit easier to understand I
> > guess, so that would be a case-by-case analysis.  Saying that, the
> > proposed patch seems right while it makes slightly easier to
> > understand the footer print part.
>
> It also aligns the code with print_unaligned_vertical(), but I can't see
> why
> need_recordsep = true;
> is a no-op here (scan-build dislikes only need_recordsep = false;).
> I suspect that removing that line will change the behaviour in cases when
> need_recordsep = false after the loop "print cells" and the loop
> "for (footers)" is executed.
>
Not sure about this.
I tested with patch and the results is:

psql -U postgres --no-align
psql (16beta1)
WARNING: Console code page (850) differs from Windows code page (1252)
 8-bit characters might not work correctly. See psql reference
 page "Notes for Windows users" for details.
Type "help" for help.

postgres=# select * from pgbench_accounts limit 100;
aid|bid|abalance|filler
1|1|0|
2|1|0|
3|1|0|
4|1|0|
5|1|0|
6|1|0|
7|1|0|
8|1|0|
9|1|0|
etc, etc

psql -U postgres --no-align -P recordsep=";"
psql (16beta1)
WARNING: Console code page (850) differs from Windows code page (1252)
 8-bit characters might not work correctly. See psql reference
 page "Notes for Windows users" for details.
Type "help" for help.

postgres=# select * from pgbench_accounts limit 100;
aid|bid|abalance|filler;1|1|0|
   ;2|1|0|
   ;3|1|0|

 ;4|1|0|
 ;5|1|0|
 ;6|1|0|
 ;7|1|0|
 ;8|1|0|

 ;9|1|0|
 ;10|1|0|
 ;11|1|0|
 ;12|1|0|

 ;13|1|0|
 ;14|1|0|
 ;15|1|0|
 ;16|1|0|
 ;17|1|0|
etc, etc

regards,
Ranier Vilela


>
> Best regards,
> Alexander
>


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-03 Thread Alexander Lakhin

Hi Michael,

04.06.2023 01:42, Michael Paquier wrote:

On Sat, Jun 03, 2023 at 03:00:01PM +0300, Alexander Lakhin wrote:

Clang' scan-build detects 58 errors "Dead assignment", including that one.
Maybe it would be more sensible to eliminate all errors of this class?

Depends on if this makes any code changed a bit easier to understand I
guess, so that would be a case-by-case analysis.  Saying that, the
proposed patch seems right while it makes slightly easier to
understand the footer print part.


It also aligns the code with print_unaligned_vertical(), but I can't see why
need_recordsep = true;
is a no-op here (scan-build dislikes only need_recordsep = false;).
I suspect that removing that line will change the behaviour in cases when
need_recordsep = false after the loop "print cells" and the loop
"for (footers)" is executed.

Best regards,
Alexander




Re: Avoid unused value (src/fe_utils/print.c)

2023-06-03 Thread Michael Paquier
On Sat, Jun 03, 2023 at 03:00:01PM +0300, Alexander Lakhin wrote:
> Clang' scan-build detects 58 errors "Dead assignment", including that one.
> Maybe it would be more sensible to eliminate all errors of this class?

Depends on if this makes any code changed a bit easier to understand I
guess, so that would be a case-by-case analysis.  Saying that, the
proposed patch seems right while it makes slightly easier to
understand the footer print part.
--
Michael


signature.asc
Description: PGP signature


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-03 Thread Ranier Vilela
Em sáb., 3 de jun. de 2023 às 09:00, Alexander Lakhin 
escreveu:

> Hello Ranier,
>
> 03.06.2023 13:14, Ranier Vilela wrote:
> > Hi,
> >
> > This is for Postgres 17 (head).
> >
> > Per Coverity.
> > At function print_unaligned_text, variable "need_recordsep", is
> > unnecessarily set to true and false.
>
> Clang' scan-build detects 58 errors "Dead assignment", including that one.
> Maybe it would be more sensible to eliminate all errors of this class?
>
Hi Alexander,

Sure.
I hope that when you or I are a committer,
we can fix a whole class of bugs together.

best regards,
Ranier Vilela


Re: Avoid unused value (src/fe_utils/print.c)

2023-06-03 Thread Alexander Lakhin

Hello Ranier,

03.06.2023 13:14, Ranier Vilela wrote:

Hi,

This is for Postgres 17 (head).

Per Coverity.
At function print_unaligned_text, variable "need_recordsep", is
unnecessarily set to true and false.


Clang' scan-build detects 58 errors "Dead assignment", including that one.
Maybe it would be more sensible to eliminate all errors of this class?

Best regards,
Alexander




Avoid unused value (src/fe_utils/print.c)

2023-06-03 Thread Ranier Vilela
Hi,

This is for Postgres 17 (head).

Per Coverity.
At function print_unaligned_text, variable "need_recordsep", is
unnecessarily set to true and false.

Attached a trivial fix patch.

regards,
Ranier Vilela


avoid-unused-value-print.patch
Description: Binary data