pgbench -M option can be specified more than once

Started by Tatsuo Ishiialmost 8 years ago8 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t39620
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 28, 2026 at 05:01 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t39620_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t39620_1 && git checkout t39620_1

Patchset v1 (message #1) is on t39620_1

Jump to latest
#1Tatsuo Ishii
ishii@postgresql.org

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once. For example,

$ pgbench -p 11002 -M extended -S -M prepared test
starting vacuum...end.
transaction type: <builtin: select only>
scaling factor: 1
query mode: prepared
number of clients: 1
number of threads: 1
number of transactions per client: 10
number of transactions actually processed: 10/10
latency average = 0.490 ms
tps = 2040.372858 (including connections establishing)
tps = 3920.541599 (excluding connections establishing)

In this case the last "-M prepared" was chosen as the query mode. This
is sloppy because we cannot actually choose different -M at the same
time.

Attached is a patch to detect such an error.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp

Attachments:

t39620_1
pgbench-query-mode.difftext/x-patch; charset=us-asciiDownload+7-0
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tatsuo Ishii (#1)
Re: pgbench -M option can be specified more than once

Tatsuo Ishii <ishii@sraoss.co.jp> writes:

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once. For example,

I think that's true of just about every option in all of our programs.
Why is this one instance so much worse than others that it deserves
to be handled differently?

regards, tom lane

#3Tatsuo Ishii
ishii@postgresql.org
In reply to: Tom Lane (#2)
Re: pgbench -M option can be specified more than once

Tatsuo Ishii <ishii@sraoss.co.jp> writes:

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once. For example,

I think that's true of just about every option in all of our programs.
Why is this one instance so much worse than others that it deserves
to be handled differently?

One of my colleagues actually believed that if both "-M extended" and
"-M prepared" were specified, pgbench runs in mixture of those
modes. So I felt avoiding such misunderstanding is more important.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp

#4Isaac Morland
isaac.morland@gmail.com
In reply to: Tatsuo Ishii (#3)
Re: pgbench -M option can be specified more than once

In many cases, it is handy to be able to specify an option in an alias, but
still be able to override on the actual command line.

I can't say whether that is useful with this specific option, but it seems
the same debate could be had about almost any option. I'm pretty sure the
existing behaviour is consistent with other options, with the exception of
a few (e.g. pg_dump --table), which are explicitly documented as being
cumulative.

On Fri, 2 Nov 2018 at 21:12, Tatsuo Ishii <ishii@sraoss.co.jp> wrote:

Show quoted text

Tatsuo Ishii <ishii@sraoss.co.jp> writes:

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once. For example,

I think that's true of just about every option in all of our programs.
Why is this one instance so much worse than others that it deserves
to be handled differently?

One of my colleagues actually believed that if both "-M extended" and
"-M prepared" were specified, pgbench runs in mixture of those
modes. So I felt avoiding such misunderstanding is more important.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp

#5Andres Freund
andres@anarazel.de
In reply to: Tatsuo Ishii (#3)
Re: pgbench -M option can be specified more than once

Hi,

On 2018-11-03 10:12:14 +0900, Tatsuo Ishii wrote:

Tatsuo Ishii <ishii@sraoss.co.jp> writes:

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once. For example,

I think that's true of just about every option in all of our programs.
Why is this one instance so much worse than others that it deserves
to be handled differently?

One of my colleagues actually believed that if both "-M extended" and
"-M prepared" were specified, pgbench runs in mixture of those
modes. So I felt avoiding such misunderstanding is more important.

I regularly specify options multiple times, and I'd hate for that to not
work anymore. It's really useful to set defaults for scripts that then
can be overwritten by the caller by passing on "$@" (i.e. all script
arguments).

Greetings,

Andres Freund

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#5)
Re: pgbench -M option can be specified more than once

Andres Freund <andres@anarazel.de> writes:

On 2018-11-03 10:12:14 +0900, Tatsuo Ishii wrote:

One of my colleagues actually believed that if both "-M extended" and
"-M prepared" were specified, pgbench runs in mixture of those
modes. So I felt avoiding such misunderstanding is more important.

I regularly specify options multiple times, and I'd hate for that to not
work anymore. It's really useful to set defaults for scripts that then
can be overwritten by the caller by passing on "$@" (i.e. all script
arguments).

Yeah, there's an ancient tradition that "last switch wins" when receiving
conflicting command-line options. I think we should tread very carefully
in breaking that.

regards, tom lane

#7Fabien COELHO
coelho@cri.ensmp.fr
In reply to: Tatsuo Ishii (#1)
Re: pgbench -M option can be specified more than once

Hello Tatsuo-san,

While playing with pgbench, I found multiple "-M query_mode" can be
set more than once.

As already said by others, the "last one win" is somehow a useful feature,
so I'd prefer avoiding erroring out on this one.

This could leave:

(1) improving pgbench doc by spelling out the last one win behavior, but
this is rather standard ;

(2) only warning when this accurs, but that would become noisy for
legitimate uses ;

(3) doing nothing about it.

--
Fabien.

#8Tatsuo Ishii
ishii@postgresql.org
In reply to: Tom Lane (#6)
Re: pgbench -M option can be specified more than once

Andres Freund <andres@anarazel.de> writes:

On 2018-11-03 10:12:14 +0900, Tatsuo Ishii wrote:

One of my colleagues actually believed that if both "-M extended" and
"-M prepared" were specified, pgbench runs in mixture of those
modes. So I felt avoiding such misunderstanding is more important.

I regularly specify options multiple times, and I'd hate for that to not
work anymore. It's really useful to set defaults for scripts that then
can be overwritten by the caller by passing on "$@" (i.e. all script
arguments).

Yeah, there's an ancient tradition that "last switch wins" when receiving
conflicting command-line options. I think we should tread very carefully
in breaking that.

Yes, I think that is a fair argument. Proposal withdrawn.

Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp