Re: pgbench - refactor init functions with buffers - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: pgbench - refactor init functions with buffers
Date
Msg-id 4522fb77-de4f-6357-725c-66ce9f012f73@iki.fi
Whole thread Raw
In response to Re: pgbench - refactor init functions with buffers  (Fabien COELHO <coelho@cri.ensmp.fr>)
Responses Re: pgbench - refactor init functions with buffers  (Fabien COELHO <coelho@cri.ensmp.fr>)
List pgsql-hackers
On 09/07/2020 10:05, Fabien COELHO wrote:
>> in favor of *PQExpBuffer().
> 
> Attached v7 is rebased v5 which uses PQExpBuffer, per cfbot.

Thanks! I pushed this with small changes:

- I left out the changes to executeStatement(). I'm not quite convinced 
it's a good idea or worth it, and it's unrelated to the main part of 
this patch, so let's handle that separately.

- I also left out changes to use the C99-style "for (int i = 0; ...)" 
construct. I think that's a good change for readability, but again 
unrelated to this and hardly worth changing existing code for.

- I inlined the append_tablespace() function back to the callers. And I 
did the same to the append_fillfactor() function, too. It seems more 
readable to just call appendPQExpBuffer() diretly, than encapulate the 
single appendPQExpBuffer() call in a helper function.

> @@ -3880,15 +3868,16 @@ initGenerateDataClientSide(PGconn *con)
>  
>      INSTR_TIME_SET_CURRENT(start);
>  
> +    /* printf overheads should probably be avoided... */
>      for (k = 0; k < (int64) naccounts * scale; k++)
>      {
>          int64        j = k + 1;
>  
>          /* "filler" column defaults to blank padded empty string */
> -        snprintf(sql, sizeof(sql),
> -                 INT64_FORMAT "\t" INT64_FORMAT "\t%d\t\n",
> -                 j, k / naccounts + 1, 0);
> -        if (PQputline(con, sql))
> +        printfPQExpBuffer(&sql,
> +                          INT64_FORMAT "\t" INT64_FORMAT "\t%d\t\n",
> +                          j, k / naccounts + 1, 0);
> +        if (PQputline(con, sql.data))
>          {
>              pg_log_fatal("PQputline failed");
>              exit(1);

Can you elaborate what you meant by the new "print overheads should 
probably be avoided" comment? I left that out since it seems unrelated 
to switching to PQExpBuffer.

- Heikki



pgsql-hackers by date:

Previous
From: Greg Nancarrow
Date:
Subject: Re: Libpq support to connect to standby server as priority
Next
From: Craig Ringer
Date:
Subject: PoC patch: expose TCP socket stats for walsenders