Re: pgbench - doCustom cleanup

Alvaro Herrera <alvherre@2ndquadrant.com>

From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: "Jamison, Kirk" <k.jamison@jp.fujitsu.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2018-11-21T18:08:40Z
Lists: pgsql-hackers
On 2018-Nov-20, Fabien COELHO wrote:

> > On INSTR_TIME_SET_CURRENT_LAZY(), you cannot just put an "if" inside a
> > macro -- consider this:
> > 	if (foo)
> > 		INSTR_TIME_SET_CURRENT_LAZY(bar);
> > 	else
> > 		something_else();
> > Which "if" is the else now attached to?  Now maybe the C standard has an
> > answer for that (I don't know what it is), but it's hard to read and
> > likely the compiler will complain anyway.  I wrapped it in "do { }
> > while(0)" as is customary.
> 
> Indeed, good catch.

Actually, reviewing this bit again, I realized that it should be a
statement that evaluates to whether the change was made or not -- this
way, it can be used in one existing place.  Pushed that way.  (I
verified that InstrStartNode fails in the expected way if you call it
twice.)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Commits

  1. pgbench: doExecuteCommand -> executeMetaCommand

  2. Rework the pgbench state machine code for clarity

  3. instr_time.h: add INSTR_TIME_SET_CURRENT_LAZY

  4. pgbench: introduce a RandomState struct