Hello devs,
The minor attached patch $SUBJECT, so that it can be inspected easily,
instead of having to look at the source code or whatever.
sh> pgbench --list select-only
-- select-only: <builtin: select only>
\set aid random(1, 100000 * :scale)
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
The builtin list output is also slightly improved:
sh> pgbench -b list
Available builtin scripts:
tpcb-like: <builtin: TPC-B (sort of)>
simple-update: <builtin: simple update>
select-only: <builtin: select only>
--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index ee2501be55..4b7368b05e 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -355,7 +355,6 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
</listitem>
</varlistentry>
-
<varlistentry>
<term><option>-c</option> <replaceable>clients</replaceable></term>
<term><option>--client=</option><replaceable>clients</replaceable></term>
@@ -456,6 +455,16 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--list</option><replaceable>scriptname</replaceable></term>
+ <listitem>
+ <para>
+ Show the actual code of builtin script <replaceable>scriptname</replaceable>
+ on stderr, and exit immediately.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-M</option> <replaceable>querymode</replaceable></term>
<term><option>--protocol=</option><replaceable>querymode</replaceable></term>
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 99529de52a..9f085508d9 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -651,6 +651,7 @@ usage(void)
" --progress-timestamp use Unix epoch timestamps for progress\n"
" --random-seed=SEED set random seed (\"time\", \"rand\", integer)\n"
" --sampling-rate=NUM fraction of transactions to log (e.g., 0.01 for 1%%)\n"
+ " --list=NAME show builtin script code, then exit\n"
"\nCommon options:\n"
" -d, --debug print debugging output\n"
" -h, --host=HOSTNAME database server host or socket directory\n"
@@ -4658,7 +4659,7 @@ listAvailableScripts(void)
fprintf(stderr, "Available builtin scripts:\n");
for (i = 0; i < lengthof(builtin_script); i++)
- fprintf(stderr, "\t%s\n", builtin_script[i].name);
+ fprintf(stderr, " %13s: %s\n", builtin_script[i].name, builtin_script[i].desc);
fprintf(stderr, "\n");
}
@@ -5095,6 +5096,7 @@ main(int argc, char **argv)
{"log-prefix", required_argument, NULL, 7},
{"foreign-keys", no_argument, NULL, 8},
{"random-seed", required_argument, NULL, 9},
+ {"list", required_argument, NULL, 10},
{NULL, 0, NULL, 0}
};
@@ -5447,6 +5449,13 @@ main(int argc, char **argv)
exit(1);
}
break;
+ case 10: /* list */
+ {
+ const BuiltinScript *s = findBuiltin(optarg);
+ fprintf(stderr, "-- %s: %s\n%s\n", s->name, s->desc, s->script);
+ exit(0);
+ }
+ break;
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
diff --git a/src/bin/pgbench/t/002_pgbench_no_server.pl b/src/bin/pgbench/t/002_pgbench_no_server.pl
index 69a6d03bb3..d9cf01233c 100644
--- a/src/bin/pgbench/t/002_pgbench_no_server.pl
+++ b/src/bin/pgbench/t/002_pgbench_no_server.pl
@@ -218,6 +218,15 @@ pgbench(
],
'pgbench builtin list');
+# builtin listing
+pgbench(
+ '--list se',
+ 0,
+ [qr{^$}],
+ [ qr{select-only: }, qr{SELECT abalance FROM pgbench_accounts WHERE},
+ qr{(?!UPDATE)}, qr{(?!INSERT)} ],
+ 'pgbench builtin listing');
+
my @script_tests = (
# name, err, { file => contents }