pgbench -M option can be specified more than once

Started by Tatsuo Ishiiabout 7 years ago8 messages
#1Tatsuo Ishii
ishii@sraoss.co.jp
1 attachment(s)

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:

pgbench-query-mode.difftext/x-patch; charset=us-asciiDownload
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 81bc6d8a6e..d69478b8dd 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -464,6 +464,7 @@ typedef enum QueryMode
 
 static QueryMode querymode = QUERY_SIMPLE;
 static const char *QUERYMODE[] = {"simple", "extended", "prepared"};
+bool	query_mode_already_set = false;
 
 typedef struct
 {
@@ -5149,6 +5150,12 @@ main(int argc, char **argv)
 				}
 				break;
 			case 'M':
+				if (query_mode_already_set)
+				{
+					fprintf(stderr, "query mode (-M) already set\n");
+					exit(1);
+				}
+				query_mode_already_set = true;
 				benchmarking_option_set = true;
 				for (querymode = 0; querymode < NUM_QUERYMODE; querymode++)
 					if (strcmp(optarg, QUERYMODE[querymode]) == 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@sraoss.co.jp
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@sraoss.co.jp
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