pgbench - refactor init functions with buffers

Fabien COELHO <coelho@cri.ensmp.fr>

From: Fabien COELHO <coelho@cri.ensmp.fr>
To: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2019-10-22T06:32:45Z
Lists: pgsql-hackers

Attachments

Hello,

While developing pgbench to allow partitioned tabled, I reproduced the 
string management style used in the corresponding functions, but was 
pretty unhappy with that kind of pattern:

 	snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ...)

However adding a feature is not the place for refactoring.

This patch refactors initialization functions so as to use PQExpBuffer 
where appropriate to simplify and clarify the code. SQL commands are 
generated by accumulating parts into a buffer in order, before executing 
it. I also added a more generic function to execute a statement and fail 
if the result is unexpected.

-- 
Fabien.

Commits

  1. pgbench: Use PQExpBuffer to simplify code that constructs SQL.

  2. Make command order in test more sensible