Re: Fix for Extra Parenthesis in pgbench progress message

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Tatsuo Ishii <ishii(at)postgresql(dot)org>, pgsql-release(at)lists(dot)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix for Extra Parenthesis in pgbench progress message
Date: 2025-02-07 18:02:56
Message-ID: Z6ZK0LBTInOt7VWE@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 40592e62606..b73921c36e3 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4990,6 +4990,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
for (k = 0; k < total; k++)
{
int64 j = k + 1;
+ bool printed = false;

init_row(&sql, k);
if (PQputline(con, sql.data))
@@ -5011,6 +5012,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
j, total,
(int) ((j * 100) / total),
table, elapsed_sec, remaining_sec);
+ printed = true;
}
/* let's not call the timing for each row, but only each 100 rows */
else if (use_quiet && (j % 100 == 0))
@@ -5025,6 +5027,7 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
j, total,
(int) ((j * 100) / total),
table, elapsed_sec, remaining_sec);
+ printed = true;

/* skip to the next interval */
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
@@ -5038,7 +5041,8 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
*/
if (prev_chars > chars)
fprintf(stderr, "%*c", prev_chars - chars, ' ');
- fputc(eol, stderr);
+ if (printed)
+ fputc(eol, stderr);
prev_chars = chars;
}

--
nathan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-02-07 18:10:04 Re: Fix for Extra Parenthesis in pgbench progress message
Previous Message Masahiko Sawada 2025-02-07 18:00:14 Re: Fix assert failure when decoding XLOG_PARAMETER_CHANGE on primary