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