pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedSmall miscellaneus fixes (Part II)
14+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2023-01-17 e29c565343 Remove dead code in formatting.c
2022-12-22 01be9d498f Fix operator typo in tablecmds.c
* Small miscellaneus fixes (Part II)
@ 2022-11-25 21:27 Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
0 siblings, 1 reply; 14+ messages in thread
From: Ranier Vilela @ 2022-11-25 21:27 UTC (permalink / raw)
To: pgsql-hackers
Hi.
There another assorted fixes to the head branch.
1. Avoid useless pointer increment
(src/backend/utils/activity/pgstat_shmem.c)
The pointer *p, is used in creation dsa memory,
not p + MAXALIGN(pgstat_dsa_init_size()).
2. Discard result unused (src/backend/access/transam/xlogrecovery.c)
Some compilers raise warnings about discarding return from strtoul.
3. Fix dead code (src/bin/pg_dump/pg_dump.c)
tbinfo->relkind == RELKIND_MATVIEW is always true, so "INDEX"
is never hit.
Per Coverity.
4. Fix dead code (src/backend/utils/adt/formatting.c)
Np->sign == '+', is different than "!= '-'" and is different than "!= '+'"
So the else is never hit.
Per Coverity.
5. Use boolean operator with boolean operands
(b/src/backend/commands/tablecmds.c)
regards,
Ranier Vilela
Attachments: download all (5 files, .tar.gz)
avoid_useless_pointer_increment.patch (application/octet-stream, 506B) download
diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c
index 706692862c..633e9c4059 100644
--- a/src/backend/utils/activity/pgstat_shmem.c
+++ b/src/backend/utils/activity/pgstat_shmem.c
@@ -164,7 +164,6 @@ StatsShmemInit(void)
* provides a small efficiency win.
*/
ctl->raw_dsa_area = p;
- p += MAXALIGN(pgstat_dsa_init_size());
dsa = dsa_create_in_place(ctl->raw_dsa_area,
pgstat_dsa_init_size(),
LWTRANCHE_PGSTATS_DSA, 0);
discard_strtoul_unused_result.patch (application/octet-stream, 581B) download
diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index cb07694aea..1f38d00171 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -4861,7 +4861,7 @@ check_recovery_target_timeline(char **newval, void **extra, GucSource source)
rttg = RECOVERY_TARGET_TIMELINE_NUMERIC;
errno = 0;
- strtoul(*newval, NULL, 0);
+ (void) strtoul(*newval, NULL, 0);
if (errno == EINVAL || errno == ERANGE)
{
GUC_check_errdetail("recovery_target_timeline is not a valid number.");
fix_dead_code_pg_dump.patch (application/octet-stream, 534B) download
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index da427f4d4a..8f3ded4327 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -15472,8 +15472,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
if (tbinfo->relkind == RELKIND_MATVIEW)
append_depends_on_extension(fout, q, &tbinfo->dobj,
"pg_catalog.pg_class",
- tbinfo->relkind == RELKIND_MATVIEW ?
- "MATERIALIZED VIEW" : "INDEX",
+ "MATERIALIZED VIEW",
qualrelname);
/*
fix_dead_code_formatting.patch (application/octet-stream, 565B) download
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 26f498b5df..1b25bf4725 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5693,7 +5693,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
if (IS_MINUS(Np->Num))
Np->Num->flag &= ~NUM_F_MINUS;
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
+ if (Np->sign != '+' && IS_PLUS(Np->Num))
Np->Num->flag &= ~NUM_F_PLUS;
if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == false)
use_boolean_operator_with_boolean_operands.patch (application/octet-stream, 613B) download
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 845208d662..bc4ea8b73f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8903,7 +8903,7 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
*/
newcons = AddRelationNewConstraints(rel, NIL,
list_make1(copyObject(constr)),
- recursing | is_readd, /* allow_merge */
+ recursing || is_readd, /* allow_merge */
!recursing, /* is_local */
is_readd, /* is_internal */
NULL); /* queryString not available
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
@ 2022-12-21 00:51 ` Justin Pryzby <pryzby@telsasoft.com>
2022-12-21 07:10 ` Re: Small miscellaneus fixes (Part II) Michael Paquier <michael@paquier.xyz>
2022-12-21 17:51 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
0 siblings, 3 replies; 14+ messages in thread
From: Justin Pryzby @ 2022-12-21 00:51 UTC (permalink / raw)
To: Ranier Vilela <ranier.vf@gmail.com>; +Cc: pgsql-hackers
On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> 5. Use boolean operator with boolean operands
> (b/src/backend/commands/tablecmds.c)
tablecmds.c: right. Since 074c5cfbf
pg_dump.c: right. Since b08dee24a
> 4. Fix dead code (src/backend/utils/adt/formatting.c)
> Np->sign == '+', is different than "!= '-'" and is different than "!= '+'"
> So the else is never hit.
formatting.c: I don't see the problem.
if (Np->sign != '-')
...
else if (Np->sign != '+' && IS_PLUS(Np->Num))
...
You said that the "else" is never hit, but why ?
What if sign is 0 ?
--
Justin
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
@ 2022-12-21 07:10 ` Michael Paquier <michael@paquier.xyz>
2022-12-22 14:35 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2022-12-21 07:10 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
On Tue, Dec 20, 2022 at 06:51:34PM -0600, Justin Pryzby wrote:
> On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> > 5. Use boolean operator with boolean operands
> > (b/src/backend/commands/tablecmds.c)
>
> tablecmds.c: right. Since 074c5cfbf
Most of this does not seem to be really worth poking at.
newcons = AddRelationNewConstraints(rel, NIL,
list_make1(copyObject(constr)),
- recursing | is_readd, /* allow_merge */
+ recursing || is_readd, /* allow_merge */
There is no damage here, but that looks like a typo so no objections
on this one.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-21 07:10 ` Re: Small miscellaneus fixes (Part II) Michael Paquier <michael@paquier.xyz>
@ 2022-12-22 14:35 ` Ranier Vilela <ranier.vf@gmail.com>
0 siblings, 0 replies; 14+ messages in thread
From: Ranier Vilela @ 2022-12-22 14:35 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; +Cc: Justin Pryzby <pryzby@telsasoft.com>; pgsql-hackers
Em qua., 21 de dez. de 2022 às 04:10, Michael Paquier <michael@paquier.xyz>
escreveu:
> On Tue, Dec 20, 2022 at 06:51:34PM -0600, Justin Pryzby wrote:
> > On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> > > 5. Use boolean operator with boolean operands
> > > (b/src/backend/commands/tablecmds.c)
> >
> > tablecmds.c: right. Since 074c5cfbf
>
> Most of this does not seem to be really worth poking at.
>
> newcons = AddRelationNewConstraints(rel, NIL,
> list_make1(copyObject(constr)),
> - recursing | is_readd, /*
> allow_merge */
> + recursing || is_readd, /*
> allow_merge */
> There is no damage here, but that looks like a typo so no objections
> on this one.
>
Thanks Michael, for the commit.
regards,
Ranier Vilela
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
@ 2022-12-21 17:51 ` Ranier Vilela <ranier.vf@gmail.com>
2 siblings, 0 replies; 14+ messages in thread
From: Ranier Vilela @ 2022-12-21 17:51 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers
Thanks for looking at this.
Em ter., 20 de dez. de 2022 às 21:51, Justin Pryzby <pryzby@telsasoft.com>
escreveu:
> On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> > 5. Use boolean operator with boolean operands
> > (b/src/backend/commands/tablecmds.c)
>
> tablecmds.c: right. Since 074c5cfbf
>
> pg_dump.c: right. Since b08dee24a
>
> > 4. Fix dead code (src/backend/utils/adt/formatting.c)
> > Np->sign == '+', is different than "!= '-'" and is different than "!=
> '+'"
> > So the else is never hit.
>
> formatting.c: I don't see the problem.
>
> if (Np->sign != '-')
> ...
> else if (Np->sign != '+' && IS_PLUS(Np->Num))
> ...
>
> You said that the "else" is never hit, but why ?
>
Maybe this part of the patch is wrong.
The only case for the first if not handled is sign == '-',
sign == '-' is handled by else.
So always the "else is true", because sign == '+' is
handled by the first if.
regards,
Ranier Vilela
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
@ 2022-12-22 17:29 ` Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2 siblings, 1 reply; 14+ messages in thread
From: Ranier Vilela @ 2022-12-22 17:29 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers
Em ter., 20 de dez. de 2022 às 21:51, Justin Pryzby <pryzby@telsasoft.com>
escreveu:
> On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> > 5. Use boolean operator with boolean operands
> > (b/src/backend/commands/tablecmds.c)
>
> tablecmds.c: right. Since 074c5cfbf
>
> pg_dump.c: right. Since b08dee24a
>
> > 4. Fix dead code (src/backend/utils/adt/formatting.c)
> > Np->sign == '+', is different than "!= '-'" and is different than "!=
> '+'"
> > So the else is never hit.
>
> formatting.c: I don't see the problem.
>
> if (Np->sign != '-')
> ...
> else if (Np->sign != '+' && IS_PLUS(Np->Num))
> ...
>
> You said that the "else" is never hit, but why ?
>
This is a Coverity report.
dead_error_condition: The condition Np->Num->flag & 0x200 cannot be true.
5671 else if (Np->sign != '+' && IS_PLUS(Np->Num))
CID 1501076 (#1 of 1): Logically dead code (DEADCODE)dead_error_line: Execution
cannot reach this statement: Np->Num->flag &= 0xffffffff....
So, the dead code is because IS_PUS(Np->Num) is already tested and cannot
be true on else.
v1 patch attached.
regards,
Ranier Vilela
Attachments:
v1-fix_dead_code_formatting.patch (application/octet-stream, 550B) download
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 65746c48d2..82aad1d118 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5668,7 +5668,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
if (IS_MINUS(Np->Num))
Np->Num->flag &= ~NUM_F_MINUS;
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
+ else if (Np->sign != '+')
Np->Num->flag &= ~NUM_F_PLUS;
if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == false)
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
@ 2022-12-23 01:08 ` Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
0 siblings, 1 reply; 14+ messages in thread
From: Justin Pryzby @ 2022-12-23 01:08 UTC (permalink / raw)
To: Ranier Vilela <ranier.vf@gmail.com>; +Cc: pgsql-hackers
On Thu, Dec 22, 2022 at 02:29:11PM -0300, Ranier Vilela wrote:
> Em ter., 20 de dez. de 2022 às 21:51, Justin Pryzby <pryzby@telsasoft.com> escreveu:
>
> > On Fri, Nov 25, 2022 at 06:27:04PM -0300, Ranier Vilela wrote:
> > > 5. Use boolean operator with boolean operands
> > > (b/src/backend/commands/tablecmds.c)
> >
> > tablecmds.c: right. Since 074c5cfbf
> >
> > pg_dump.c: right. Since b08dee24a
> >
> > > 4. Fix dead code (src/backend/utils/adt/formatting.c)
> > > Np->sign == '+', is different than "!= '-'" and is different than "!=
> > '+'"
> > > So the else is never hit.
> >
> > formatting.c: I don't see the problem.
> >
> > if (Np->sign != '-')
> > ...
> > else if (Np->sign != '+' && IS_PLUS(Np->Num))
> > ...
> >
> > You said that the "else" is never hit, but why ?
>
> This is a Coverity report.
>
> dead_error_condition: The condition Np->Num->flag & 0x200 cannot be true.
> 5671 else if (Np->sign != '+' && IS_PLUS(Np->Num))
>
> CID 1501076 (#1 of 1): Logically dead code (DEADCODE)dead_error_line: Execution
> cannot reach this statement: Np->Num->flag &= 0xffffffff....
>
> So, the dead code is because IS_PUS(Np->Num) is already tested and cannot
> be true on else.
Makes sense now (in your first message, you said that the problem was
with "sign", and the patch didn't address the actual problem in
IS_PLUS()).
One can look and find that the unreachable code was introduced at
7a3e7b64a.
With your proposed change, the unreachable line is hit by regression
tests, which is an improvment. As is the change to pg_dump.c.
--
Justin
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
@ 2023-01-12 05:15 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
0 siblings, 1 reply; 14+ messages in thread
From: John Naylor @ 2023-01-12 05:15 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
On Fri, Dec 23, 2022 at 8:08 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
> Makes sense now (in your first message, you said that the problem was
> with "sign", and the patch didn't address the actual problem in
> IS_PLUS()).
>
> One can look and find that the unreachable code was introduced at
> 7a3e7b64a.
>
> With your proposed change, the unreachable line is hit by regression
> tests, which is an improvment. As is the change to pg_dump.c.
But that now reachable line just unsets a flag that we previously found
unset, right?
And if that line was unreachable, then surely the previous flag-clearing
operation is too?
5669 994426 : if (IS_MINUS(Np->Num)) // <- also always
false
5670 0 : Np->Num->flag &= ~NUM_F_MINUS;
5671 : }
5672 524 : else if (Np->sign != '+' && IS_PLUS(Np->Num))
5673 0 : Np->Num->flag &= ~NUM_F_PLUS;
https://coverage.postgresql.org/src/backend/utils/adt/formatting.c.gcov.html
I'm inclined to turn the dead unsets into asserts.
--
John Naylor
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
@ 2023-01-12 05:34 ` Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
0 siblings, 1 reply; 14+ messages in thread
From: Justin Pryzby @ 2023-01-12 05:34 UTC (permalink / raw)
To: John Naylor <john.naylor@enterprisedb.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
On Thu, Jan 12, 2023 at 12:15:24PM +0700, John Naylor wrote:
> On Fri, Dec 23, 2022 at 8:08 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
>
> > Makes sense now (in your first message, you said that the problem was
> > with "sign", and the patch didn't address the actual problem in
> > IS_PLUS()).
> >
> > One can look and find that the unreachable code was introduced at
> > 7a3e7b64a.
> >
> > With your proposed change, the unreachable line is hit by regression
> > tests, which is an improvment. As is the change to pg_dump.c.
>
> But that now reachable line just unsets a flag that we previously found
> unset, right?
Good point.
> And if that line was unreachable, then surely the previous flag-clearing
> operation is too?
>
> 5669 994426 : if (IS_MINUS(Np->Num)) // <- also always
> false
> 5670 0 : Np->Num->flag &= ~NUM_F_MINUS;
> 5671 : }
> 5672 524 : else if (Np->sign != '+' && IS_PLUS(Np->Num))
> 5673 0 : Np->Num->flag &= ~NUM_F_PLUS;
>
> https://coverage.postgresql.org/src/backend/utils/adt/formatting.c.gcov.html
>
> I'm inclined to turn the dead unsets into asserts.
To be clear - did you mean like this ?
inline patch 1: src/backend/utils/adt/formatting.c (+2/-4 lines) download inline-1.patch
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index a4b524ea3ac..848956879f5 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5662,15 +5662,13 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
}
else
{
+ Assert(!IS_MINUS(Np->Num));
+ Assert(!IS_PLUS(Np->Num));
if (Np->sign != '-')
{
if (IS_BRACKET(Np->Num) && IS_FILLMODE(Np->Num))
Np->Num->flag &= ~NUM_F_BRACKET;
- if (IS_MINUS(Np->Num))
- Np->Num->flag &= ~NUM_F_MINUS;
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
- Np->Num->flag &= ~NUM_F_PLUS;
if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == false)
Np->sign_wrote = true; /* needn't sign */
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
@ 2023-01-12 06:44 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-16 06:28 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
0 siblings, 1 reply; 14+ messages in thread
From: John Naylor @ 2023-01-12 06:44 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
On Thu, Jan 12, 2023 at 12:34 PM Justin Pryzby <pryzby@telsasoft.com> wrote:
>
> On Thu, Jan 12, 2023 at 12:15:24PM +0700, John Naylor wrote:
> > On Fri, Dec 23, 2022 at 8:08 AM Justin Pryzby <pryzby@telsasoft.com>
wrote:
> >
> > > Makes sense now (in your first message, you said that the problem was
> > > with "sign", and the patch didn't address the actual problem in
> > > IS_PLUS()).
> > >
> > > One can look and find that the unreachable code was introduced at
> > > 7a3e7b64a.
> > >
> > > With your proposed change, the unreachable line is hit by regression
> > > tests, which is an improvment. As is the change to pg_dump.c.
> >
> > But that now reachable line just unsets a flag that we previously found
> > unset, right?
>
> Good point.
>
> > And if that line was unreachable, then surely the previous flag-clearing
> > operation is too?
> >
> > 5669 994426 : if (IS_MINUS(Np->Num)) // <- also
always
> > false
> > 5670 0 : Np->Num->flag &= ~NUM_F_MINUS;
> > 5671 : }
> > 5672 524 : else if (Np->sign != '+' &&
IS_PLUS(Np->Num))
> > 5673 0 : Np->Num->flag &= ~NUM_F_PLUS;
> >
> >
https://coverage.postgresql.org/src/backend/utils/adt/formatting.c.gcov.html
> >
> > I'm inclined to turn the dead unsets into asserts.
>
> To be clear - did you mean like this ?
>
> diff --git a/src/backend/utils/adt/formatting.c
b/src/backend/utils/adt/formatting.c
> index a4b524ea3ac..848956879f5 100644
> --- a/src/backend/utils/adt/formatting.c
> +++ b/src/backend/utils/adt/formatting.c
> @@ -5662,15 +5662,13 @@ NUM_processor(FormatNode *node, NUMDesc *Num,
char *inout,
> }
> else
> {
> + Assert(!IS_MINUS(Np->Num));
> + Assert(!IS_PLUS(Np->Num));
> if (Np->sign != '-')
> {
> if (IS_BRACKET(Np->Num) &&
IS_FILLMODE(Np->Num))
> Np->Num->flag &= ~NUM_F_BRACKET;
> - if (IS_MINUS(Np->Num))
> - Np->Num->flag &= ~NUM_F_MINUS;
> }
> - else if (Np->sign != '+' && IS_PLUS(Np->Num))
> - Np->Num->flag &= ~NUM_F_PLUS;
>
> if (Np->sign == '+' && IS_FILLMODE(Np->Num) &&
IS_LSIGN(Np->Num) == false)
> Np->sign_wrote = true; /* needn't sign */
I was originally thinking of something more localized:
inline patch 1: src/backend/utils/adt/formatting.c (+0/-0 lines) download inline-1.patch
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5666,11 +5666,10 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char
*inout,
{
if (IS_BRACKET(Np->Num) && IS_FILLMODE(Np->Num))
Np->Num->flag &= ~NUM_F_BRACKET;
- if (IS_MINUS(Np->Num))
- Np->Num->flag &= ~NUM_F_MINUS;
+ Assert(!IS_MINUS(Np->Num));
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
- Np->Num->flag &= ~NUM_F_PLUS;
+ else if (Np->sign != '+')
+ Assert(!IS_PLUS(Np->Num));
...but arguably the earlier check is close enough that it's silly to assert
in the "else" branch, and I'd be okay with just nuking those lines. Another
thing that caught my attention is the assumption that unsetting a bit is so
expensive that we have to first check if it's set, so we may as well remove
"IS_BRACKET(Np->Num)" as well.
--
John Naylor
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
@ 2023-01-16 06:28 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-16 11:20 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2023-01-17 07:36 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
0 siblings, 2 replies; 14+ messages in thread
From: John Naylor @ 2023-01-16 06:28 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
I wrote:
> ...but arguably the earlier check is close enough that it's silly to
assert in the "else" branch, and I'd be okay with just nuking those lines.
Another thing that caught my attention is the assumption that unsetting a
bit is so expensive that we have to first check if it's set, so we may as
well remove "IS_BRACKET(Np->Num)" as well.
The attached is what I mean. I'll commit this this week unless there are
objections.
--
John Naylor
EDB: http://www.enterprisedb.com
Attachments:
v4-0001-Remove-dead-code-in-formatting.c.patch (text/x-patch, 1.5K) download
From 5dd409e6059be464ad635ce8cd885fc3de5d8e43 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Mon, 16 Jan 2023 13:03:22 +0700
Subject: [PATCH v4] Remove dead code in formatting.c
Remove some code guarded by IS_MINUS() or IS_PLUS(), where the entire
stanza is inside an else-block where both of these are false. This
should slightly improve test coverage.
While at it, remove coding that apparently assumes that unsetting a
bit is so expensive that we have to first check if it's already set
in the first place.
Reviewed by Justin Pryzby
Per Coverity report from Ranier Vilela
Discussion: https://www.postgresql.org/message-id/20221223010818.GP1153%40telsasoft.com
---
src/backend/utils/adt/formatting.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index a4b524ea3a..f3f4db5ef6 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -5664,13 +5664,9 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout,
{
if (Np->sign != '-')
{
- if (IS_BRACKET(Np->Num) && IS_FILLMODE(Np->Num))
+ if (IS_FILLMODE(Np->Num))
Np->Num->flag &= ~NUM_F_BRACKET;
- if (IS_MINUS(Np->Num))
- Np->Num->flag &= ~NUM_F_MINUS;
}
- else if (Np->sign != '+' && IS_PLUS(Np->Num))
- Np->Num->flag &= ~NUM_F_PLUS;
if (Np->sign == '+' && IS_FILLMODE(Np->Num) && IS_LSIGN(Np->Num) == false)
Np->sign_wrote = true; /* needn't sign */
--
2.39.0
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-16 06:28 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
@ 2023-01-16 11:20 ` Ranier Vilela <ranier.vf@gmail.com>
1 sibling, 0 replies; 14+ messages in thread
From: Ranier Vilela @ 2023-01-16 11:20 UTC (permalink / raw)
To: John Naylor <john.naylor@enterprisedb.com>; +Cc: Justin Pryzby <pryzby@telsasoft.com>; pgsql-hackers
Em seg., 16 de jan. de 2023 às 03:28, John Naylor <
john.naylor@enterprisedb.com> escreveu:
>
> I wrote:
> > ...but arguably the earlier check is close enough that it's silly to
> assert in the "else" branch, and I'd be okay with just nuking those lines.
> Another thing that caught my attention is the assumption that unsetting a
> bit is so expensive that we have to first check if it's set, so we may as
> well remove "IS_BRACKET(Np->Num)" as well.
>
> The attached is what I mean. I'll commit this this week unless there are
> objections.
>
+1 looks good to me.
regards,
Ranier Vilela
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-16 06:28 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
@ 2023-01-17 07:36 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-17 11:26 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
1 sibling, 1 reply; 14+ messages in thread
From: John Naylor @ 2023-01-17 07:36 UTC (permalink / raw)
To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: Ranier Vilela <ranier.vf@gmail.com>; pgsql-hackers
On Mon, Jan 16, 2023 at 1:28 PM John Naylor <john.naylor@enterprisedb.com>
wrote:
>
>
> I wrote:
> > ...but arguably the earlier check is close enough that it's silly to
assert in the "else" branch, and I'd be okay with just nuking those lines.
Another thing that caught my attention is the assumption that unsetting a
bit is so expensive that we have to first check if it's set, so we may as
well remove "IS_BRACKET(Np->Num)" as well.
>
> The attached is what I mean. I'll commit this this week unless there are
objections.
I've pushed this and the cosmetic fix in pg_dump. Those were the only
things I saw that had some interest, so I closed the CF entry.
--
John Naylor
EDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Small miscellaneus fixes (Part II)
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2022-12-22 17:29 ` Re: Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Re: Small miscellaneus fixes (Part II) Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-16 06:28 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
2023-01-17 07:36 ` Re: Small miscellaneus fixes (Part II) John Naylor <john.naylor@enterprisedb.com>
@ 2023-01-17 11:26 ` Ranier Vilela <ranier.vf@gmail.com>
0 siblings, 0 replies; 14+ messages in thread
From: Ranier Vilela @ 2023-01-17 11:26 UTC (permalink / raw)
To: John Naylor <john.naylor@enterprisedb.com>; +Cc: Justin Pryzby <pryzby@telsasoft.com>; pgsql-hackers
Em ter., 17 de jan. de 2023 às 04:37, John Naylor <
john.naylor@enterprisedb.com> escreveu:
>
> On Mon, Jan 16, 2023 at 1:28 PM John Naylor <john.naylor@enterprisedb.com>
> wrote:
> >
> >
> > I wrote:
> > > ...but arguably the earlier check is close enough that it's silly to
> assert in the "else" branch, and I'd be okay with just nuking those lines.
> Another thing that caught my attention is the assumption that unsetting a
> bit is so expensive that we have to first check if it's set, so we may as
> well remove "IS_BRACKET(Np->Num)" as well.
> >
> > The attached is what I mean. I'll commit this this week unless there are
> objections.
>
> I've pushed this and the cosmetic fix in pg_dump. Those were the only
> things I saw that had some interest, so I closed the CF entry.
>
Thanks for the commits.
regards,
Ranier Vilela
^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2023-01-17 11:26 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 21:27 Small miscellaneus fixes (Part II) Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 00:51 ` Justin Pryzby <pryzby@telsasoft.com>
2022-12-21 07:10 ` Michael Paquier <michael@paquier.xyz>
2022-12-22 14:35 ` Ranier Vilela <ranier.vf@gmail.com>
2022-12-21 17:51 ` Ranier Vilela <ranier.vf@gmail.com>
2022-12-22 17:29 ` Ranier Vilela <ranier.vf@gmail.com>
2022-12-23 01:08 ` Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 05:15 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-12 05:34 ` Justin Pryzby <pryzby@telsasoft.com>
2023-01-12 06:44 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-16 06:28 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-16 11:20 ` Ranier Vilela <ranier.vf@gmail.com>
2023-01-17 07:36 ` John Naylor <john.naylor@enterprisedb.com>
2023-01-17 11:26 ` Ranier Vilela <ranier.vf@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox