Skip to content

Commit d561f1c

Browse files
committed
pgbench: accept unambiguous builtin prefixes for -b
This makes it easier to use "-b se" instead of typing the full "-b select-only". Author: Fabien Coelho Reviewed-by: Michaël Paquier
1 parent 2c83f43 commit d561f1c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

doc/src/sgml/ref/pgbench.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
269269
Add the specified builtin script to the list of executed scripts.
270270
Available builtin scripts are: <literal>tpcb-like</>,
271271
<literal>simple-update</> and <literal>select-only</>.
272+
Unambiguous prefixes of builtin names are accepted.
272273
With special name <literal>list</>, show the list of builtin scripts
273274
and exit immediately.
274275
</para>

src/bin/pgbench/pgbench.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,22 +2746,36 @@ listAvailableScripts(void)
27462746
fprintf(stderr, "\n");
27472747
}
27482748

2749+
/* return builtin script "name" if unambiguous */
27492750
static char *
27502751
findBuiltin(const char *name, char **desc)
27512752
{
2752-
int i;
2753+
int i,
2754+
found = 0,
2755+
len = strlen(name);
2756+
char *commands = NULL;
27532757

27542758
for (i = 0; i < N_BUILTIN; i++)
27552759
{
2756-
if (strncmp(builtin_script[i].name, name,
2757-
strlen(builtin_script[i].name)) == 0)
2760+
if (strncmp(builtin_script[i].name, name, len) == 0)
27582761
{
27592762
*desc = builtin_script[i].desc;
2760-
return builtin_script[i].commands;
2763+
commands = builtin_script[i].commands;
2764+
found++;
27612765
}
27622766
}
27632767

2764-
fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
2768+
/* ok, unambiguous result */
2769+
if (found == 1)
2770+
return commands;
2771+
2772+
/* error cases */
2773+
if (found == 0)
2774+
fprintf(stderr, "no builtin script found for name \"%s\"\n", name);
2775+
else /* found > 1 */
2776+
fprintf(stderr,
2777+
"ambiguous builtin name: %d builtin scripts found for prefix \"%s\"\n", found, name);
2778+
27652779
listAvailableScripts();
27662780
exit(1);
27672781
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy