Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tgSnv-00AuLi-SU for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2025 18:10:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tgSnu-0041mM-OB for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Feb 2025 18:10:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tgSnu-0041lh-E6 for pgsql-hackers@lists.postgresql.org; Fri, 07 Feb 2025 18:10:14 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tgSnr-004PNh-2U; Fri, 07 Feb 2025 18:10:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 517IA4WS1457694; Fri, 7 Feb 2025 13:10:04 -0500 From: Tom Lane To: Nathan Bossart cc: Andres Freund , Fujii Masao , Tatsuo Ishii , pgsql-release@lists.postgresql.org, pgsql-hackers@postgresql.org Subject: Re: Fix for Extra Parenthesis in pgbench progress message In-reply-to: References: <85fe426d-248a-47f7-8784-22af811ee572@oss.nttdata.com> <20241108.114713.484828673471024549.ishii@postgresql.org> <95f1100e-e59b-41b7-a406-f865c2e69db7@oss.nttdata.com> <20241125.083155.1820744655877715597.ishii@postgresql.org> <4k4drkh7bcmdezq6zbkhp25mnrzpswqi2o75d5uv2eeg3aq6q7@b7kqdmzzwzgb> <1456496.1738951118@sss.pgh.pa.us> Comments: In-reply-to Nathan Bossart message dated "Fri, 07 Feb 2025 12:02:56 -0600" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1457602.1738951747.0@sss.pgh.pa.us> Date: Fri, 07 Feb 2025 13:10:04 -0500 Message-ID: <1457693.1738951804@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1457602.1738951747.1@sss.pgh.pa.us> Nathan Bossart writes: > On Fri, Feb 07, 2025 at 12:58:38PM -0500, Tom Lane wrote: >> Let me have a go at fixing it, and if it turns out to be harder >> than I think, I'll revert it instead. > Oops, I was already taking a look at this. I figured it'd just be > something like the following, although maybe there's a more elegant way. Well, the stuff with prev_chars really ought to be skipped as well. (Yeah, it's probably a no-op, but readers shouldn't have to figure that out.) My thought was that duplicating the logic isn't so bad, as attached. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="pgbench-fix.patch"; charset="us-ascii" Content-ID: <1457602.1738951747.2@sss.pgh.pa.us> Content-Description: pgbench-fix.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 40592e6260..f303bdeec8 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -5011,6 +5011,16 @@ initPopulateTable(PGconn *con, const char *table, i= nt64 base, j, total, (int) ((j * 100) / total), table, elapsed_sec, remaining_sec); + + /* + * If the previous progress message is longer than the current + * one, add spaces to the current line to fully overwrite any + * remaining characters from the previous message. + */ + if (prev_chars > chars) + fprintf(stderr, "%*c", prev_chars - chars, ' '); + fputc(eol, stderr); + prev_chars =3D chars; } /* let's not call the timing for each row, but only each 100 rows */ else if (use_quiet && (j % 100 =3D=3D 0)) @@ -5026,20 +5036,20 @@ initPopulateTable(PGconn *con, const char *table, = int64 base, (int) ((j * 100) / total), table, elapsed_sec, remaining_sec); = + /* + * If the previous progress message is longer than the current + * one, add spaces to the current line to fully overwrite any + * remaining characters from the previous message. + */ + if (prev_chars > chars) + fprintf(stderr, "%*c", prev_chars - chars, ' '); + fputc(eol, stderr); + prev_chars =3D chars; + /* skip to the next interval */ log_interval =3D (int) ceil(elapsed_sec / LOG_STEP_SECONDS); } } - - /* - * If the previous progress message is longer than the current one, - * add spaces to the current line to fully overwrite any remaining - * characters from the previous message. - */ - if (prev_chars > chars) - fprintf(stderr, "%*c", prev_chars - chars, ' '); - fputc(eol, stderr); - prev_chars =3D chars; } = if (chars !=3D 0 && eol !=3D '\n') ------- =_aaaaaaaaaa0--