Re: shadow variables - pg15 edition

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: Re: shadow variables - pg15 edition
Date: 2022-10-05 22:46:28
Message-ID: CAApHDvqESZZxLrqx==J0qQoQmL=ki40+jC6JZZ0o-StzBq_cMg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 6 Oct 2022 at 02:34, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
> A simpler idea might be to just remove the inner declaration, and have
> that block set the outer var. There's no damage, since the block is
> going to end and not access the previous value anymore.
>
> diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
> index aa1a3541fe..91a067859b 100644
> --- a/src/bin/pgbench/pgbench.c
> +++ b/src/bin/pgbench/pgbench.c
> @@ -7506,7 +7506,7 @@ threadRun(void *arg)
> /* progress report is made by thread 0 for all threads */
> if (progress && thread->tid == 0)
> {
> - pg_time_usec_t now = pg_time_now();
> + now = pg_time_now(); /* not lazy; clobbers outer value */

I didn't want to do it that way because all this code is in a while
loop and the outer "now" will be reused after it's set by the code
above. It's not really immediately obvious to me what repercussions
that would have, but it didn't seem worth taking any risks.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2022-10-05 22:50:27 Re: shadow variables - pg15 edition
Previous Message Greg Nancarrow 2022-10-05 22:34:02 pg_statsinfo - PG15 support?