pgbench-script-stats-18-e.patch
text/x-diff
Filename: pgbench-script-stats-18-e.patch
Type: text/x-diff
Part: 1
Patch
Format: unified
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pgbench.sgml | 3 | 0 |
| src/bin/pgbench/pgbench.c | 19 | 6 |
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index 780a520..82e217a 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -271,6 +271,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
probability of drawing the script. If not specified, it is set to 1.
Available builtin scripts are: <literal>tpcb-like</>,
<literal>simple-update</> and <literal>select-only</>.
+ The provided <replaceable>scriptname</> needs only be an unambiguous
+ prefix of the builtin name, hence <literal>si</> would be enough to
+ select <literal>simple-update</>.
With special name <literal>list</>, show the list of builtin scripts
and exit immediately.
</para>
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index da4f05c..e394c1d 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2681,20 +2681,33 @@ listAvailableScripts(void)
fprintf(stderr, "\n");
}
-/* return builtin script "name", or fail if not found */
+/* return commands for selected builtin script, if unambiguous */
static script_t *
findBuiltin(const char *name)
{
- int i;
+ int i, found = 0, len = strlen(name);
+ script_t *script = NULL;
for (i = 0; i < N_BUILTIN; i++)
{
- if (strncmp(builtin_script[i].name, name,
- strlen(builtin_script[i].name)) == 0)
- return & builtin_script[i];
+ if (strncmp(builtin_script[i].name, name, len) == 0)
+ {
+ script = & builtin_script[i];
+ found++;
+ }
}
- fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
+ /* ok, unambiguous result */
+ if (found == 1)
+ return script;
+
+ /* error cases */
+ if (found == 0)
+ fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
+ else /* found > 1 */
+ fprintf(stderr,
+ "%d builtin scripts found for prefix \"%s\"\n", found, name);
+
listAvailableScripts();
exit(1);
}