pgbench: introduce a new automatic variable 'client_number'

Lists: pgsql-hackers
From: Gurjeet Singh <gurjeet(at)singh(dot)im>
To: PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: pgbench: introduce a new automatic variable 'client_number'
Date: 2013-06-06 03:53:26
Message-ID: CABwTF4U2+jUdSVEWGdjbPsTsgJbfjL5n0nwdxPWXb=ONMg3hSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Please find attached a patch for pgbench that introduces a new
auto-variable 'client_number'. Following in the footsteps of 'scale'
auto-variable, this is not declared if the user has specified this variable
using -D switch.

Since 'clientid' is a very common name a user can use for their own
script's variable, I chose to call this auto-variable client_number; just
to avoid conflicts.

This variable can come in handy when you want to use a different expression
in a query depending on which client is executing it. An example custom
transaction is attached, where the UPDATE statement from any given client
always updates the same logical row.

Best regards,
--
Gurjeet Singh

http://gurjeet.singh.im/

EnterpriseDB Inc.

Attachment Content-Type Size
pgbench_add_cleint_number_variable.patch application/octet-stream 2.3 KB
test_update.sql application/octet-stream 67 bytes

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>
Cc: PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgbench: introduce a new automatic variable 'client_number'
Date: 2013-06-09 08:50:08
Message-ID: 51B441C0.5050501@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06.06.2013 06:53, Gurjeet Singh wrote:
> Please find attached a patch for pgbench that introduces a new
> auto-variable 'client_number'. Following in the footsteps of 'scale'
> auto-variable, this is not declared if the user has specified this variable
> using -D switch.
>
> Since 'clientid' is a very common name a user can use for their own
> script's variable, I chose to call this auto-variable client_number; just
> to avoid conflicts.

Hmm, I'm not sure I care too much about that, to be honest. We have
'scale' as an auto-variable as well, which is also a common word. Also,
if there's an existing script out there that does "\set client_id ...",
it will override the automatic value, and work as it used to.

Another reason to name it "client_id" is that in the pgbench -l log
format, the documentation calls the first column "client_id". Makes
sense to call the auto-variable the same.

I think you forgot to compile with the patch, because there's a
semicolon missing ;-). I moved the code around a bit, setting the
variable next to where :scale is set; that's more readable. In the docs,
I split the descriptions of :scale and :client_id into a table.

I'll commit the attached as soon as the tree opens for 9.4 development.

- Heikki

Attachment Content-Type Size
pgbench-client_id-2.patch text/x-diff 2.7 KB