Re: [HACKERS] pgbench - allow to store select results into variables

Fabien COELHO <coelho@cri.ensmp.fr>

From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Michael Paquier <michael@paquier.xyz>, Stephen Frost <sfrost@snowman.net>, Andrew Dunstan <andrew.dunstan@2ndquadrant.com>, PostgreSQL Developers <pgsql-hackers@postgresql.org>
Date: 2019-01-10T09:12:26Z
Lists: pgsql-hackers

Attachments

Hello Alvaro,

> Here are my proposed final changes.

Thanks again for improving the patch!

> I noticed that you were allocating the prefixes for all cases even when 
> there were no cset/gset in the command; I changed it to delay the 
> allocation until needed.

Ok, why not.

> I also noticed you were skipping the Meta enum dance for no good reason;

Indeed. I think that the initial version of the patch was before the 
"dance" was added, and it did not keep up with it.

> added that makes conditionals simpler.  The read_response routine seemed 
> misplaced and I gave it a name in a style closer to the rest of the 
> pgbench code.

Fine.

> Also, you were missing to free the ->lines pqexpbuffer when the command 
> is discarded.  I grant that the free_command() stuff might be bogus 
> since it's only tested with a command that's barely initialized, but it 
> seems better to make it bogus in this way (fixable if we ever extend its 
> use) than to forever leak memory silently.

Ok.

However, I switched "pg_free" to "termPQExpBuffer", which seems more 
appropriate, even if it just does the same thing. I also ensured that 
prefixes are allocated & freed. I've commented about expr which is not 
freed.

> I didn't test this beyond running "make check".

That's a good start.

I'm not keen on having the command array size checked and updated *after* 
the command is appended, even if the initial allocation ensures that there 
is no overflow, but I let it as is.

Further tests did not yield any new issue.

Attached a v29 with the above minor changes wrt your version.

-- 
Fabien.

Commits

  1. pgbench: Remove \cset

  2. pgbench: add \cset and \gset commands

  3. Adjust pgbench to allow non-ASCII characters in variable names.

  4. Refactor script execution state machine in pgbench.

  5. Allow empty queries in pgbench.