From ad9566470b1ba63167d1dc7ae2cb52d88a448f76 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 29 Mar 2016 12:08:49 -0400 Subject: [PATCH] pgbench: Remove \setrandom. You can now do the same thing via \set using the appropriate function, either random(), random_gaussian(), or random_exponential(), depending on the desired distribution. This is not backward-compatible, but per discussion, it's worth it to avoid having the old syntax hang around forever. Fabien Coelho, reviewed by Michael Paquier, and adjusted by me. --- doc/src/sgml/ref/pgbench.sgml | 54 ---------- src/bin/pgbench/pgbench.c | 181 +--------------------------------- 2 files changed, 2 insertions(+), 233 deletions(-) diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml index 4ceddae681..c5399ff952 100644 --- a/doc/src/sgml/ref/pgbench.sgml +++ b/doc/src/sgml/ref/pgbench.sgml @@ -836,60 +836,6 @@ pgbench options dbname - - - \setrandom varname min max [ uniform | { gaussian | exponential } parameter ] - - - - - Sets variable varname to a random integer value - between the limits min and max inclusive. - Each limit can be either an integer constant or a - :variablename reference to a variable - having an integer value. - - - - - - - \setrandom n 1 10 or \setrandom n 1 10 uniform - is equivalent to \set n random(1, 10) and uses a uniform - distribution. - - - - - - \setrandom n 1 10 exponential 3.0 is equivalent to - \set n random_exponential(1, 10, 3.0) and uses an - exponential distribution. - - - - - - \setrandom n 1 10 gaussian 2.0 is equivalent to - \set n random_gaussian(1, 10, 2.0), and uses a gaussian - distribution. - - - - - See the documentation of these functions below for further information - about the precise shape of these distributions, depending on the value - of the parameter. - - - - Example: - -\setrandom aid 1 :naccounts gaussian 5.0 - - - - \sleep number [ us | ms | s ] diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 4cd5513fc6..90e538cedc 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -1941,148 +1941,7 @@ top: fprintf(stderr, "\n"); } - /* - * Note: this section could be removed, as the same functionnality - * is available through \set xxx random_gaussian(...) - */ - if (pg_strcasecmp(argv[0], "setrandom") == 0) - { - char *var; - int64 min, - max; - double parameter = 0; - char res[64]; - - if (*argv[2] == ':') - { - if ((var = getVariable(st, argv[2] + 1)) == NULL) - { - fprintf(stderr, "%s: undefined variable \"%s\"\n", - argv[0], argv[2]); - st->ecnt++; - return true; - } - min = strtoint64(var); - } - else - min = strtoint64(argv[2]); - - if (*argv[3] == ':') - { - if ((var = getVariable(st, argv[3] + 1)) == NULL) - { - fprintf(stderr, "%s: undefined variable \"%s\"\n", - argv[0], argv[3]); - st->ecnt++; - return true; - } - max = strtoint64(var); - } - else - max = strtoint64(argv[3]); - - if (max < min) - { - fprintf(stderr, "%s: \\setrandom maximum is less than minimum\n", - argv[0]); - st->ecnt++; - return true; - } - - /* - * Generate random number functions need to be able to subtract - * max from min and add one to the result without overflowing. - * Since we know max > min, we can detect overflow just by - * checking for a negative result. But we must check both that the - * subtraction doesn't overflow, and that adding one to the result - * doesn't overflow either. - */ - if (max - min < 0 || (max - min) + 1 < 0) - { - fprintf(stderr, "%s: \\setrandom range is too large\n", - argv[0]); - st->ecnt++; - return true; - } - - if (argc == 4 || /* uniform without or with "uniform" keyword */ - (argc == 5 && pg_strcasecmp(argv[4], "uniform") == 0)) - { -#ifdef DEBUG - printf("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n", min, max, getrand(thread, min, max)); -#endif - snprintf(res, sizeof(res), INT64_FORMAT, getrand(thread, min, max)); - } - else if (argc == 6 && - ((pg_strcasecmp(argv[4], "gaussian") == 0) || - (pg_strcasecmp(argv[4], "exponential") == 0))) - { - if (*argv[5] == ':') - { - if ((var = getVariable(st, argv[5] + 1)) == NULL) - { - fprintf(stderr, "%s: invalid parameter: \"%s\"\n", - argv[0], argv[5]); - st->ecnt++; - return true; - } - parameter = strtod(var, NULL); - } - else - parameter = strtod(argv[5], NULL); - - if (pg_strcasecmp(argv[4], "gaussian") == 0) - { - if (parameter < MIN_GAUSSIAN_PARAM) - { - fprintf(stderr, "gaussian parameter must be at least %f (not \"%s\")\n", MIN_GAUSSIAN_PARAM, argv[5]); - st->ecnt++; - return true; - } -#ifdef DEBUG - printf("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n", - min, max, - getGaussianRand(thread, min, max, parameter)); -#endif - snprintf(res, sizeof(res), INT64_FORMAT, - getGaussianRand(thread, min, max, parameter)); - } - else if (pg_strcasecmp(argv[4], "exponential") == 0) - { - if (parameter <= 0.0) - { - fprintf(stderr, - "exponential parameter must be greater than zero (not \"%s\")\n", - argv[5]); - st->ecnt++; - return true; - } -#ifdef DEBUG - printf("min: " INT64_FORMAT " max: " INT64_FORMAT " random: " INT64_FORMAT "\n", - min, max, - getExponentialRand(thread, min, max, parameter)); -#endif - snprintf(res, sizeof(res), INT64_FORMAT, - getExponentialRand(thread, min, max, parameter)); - } - } - else /* this means an error somewhere in the parsing phase... */ - { - fprintf(stderr, "%s: invalid arguments for \\setrandom\n", - argv[0]); - st->ecnt++; - return true; - } - - if (!putVariable(st, argv[0], argv[1], res)) - { - st->ecnt++; - return true; - } - - st->listen = true; - } - else if (pg_strcasecmp(argv[0], "set") == 0) + if (pg_strcasecmp(argv[0], "set") == 0) { char res[64]; PgBenchExpr *expr = commands[st->state]->expr; @@ -2880,43 +2739,7 @@ process_backslash_command(PsqlScanState sstate, const char *source) start_offset, end_offset); - if (pg_strcasecmp(my_command->argv[0], "setrandom") == 0) - { - /*-------- - * parsing: - * \setrandom variable min max [uniform] - * \setrandom variable min max (gaussian|exponential) parameter - */ - - if (my_command->argc < 4) - syntax_error(source, lineno, my_command->line, my_command->argv[0], - "missing arguments", NULL, -1); - - if (my_command->argc == 4 || /* uniform without/with "uniform" - * keyword */ - (my_command->argc == 5 && - pg_strcasecmp(my_command->argv[4], "uniform") == 0)) - { - /* nothing to do */ - } - else if ( /* argc >= 5 */ - (pg_strcasecmp(my_command->argv[4], "gaussian") == 0) || - (pg_strcasecmp(my_command->argv[4], "exponential") == 0)) - { - if (my_command->argc < 6) - syntax_error(source, lineno, my_command->line, my_command->argv[0], - "missing parameter", NULL, -1); - else if (my_command->argc > 6) - syntax_error(source, lineno, my_command->line, my_command->argv[0], - "too many arguments", NULL, - offsets[6] - start_offset); - } - else /* unrecognized distribution argument */ - syntax_error(source, lineno, my_command->line, my_command->argv[0], - "unexpected argument", my_command->argv[4], - offsets[4] - start_offset); - } - else if (pg_strcasecmp(my_command->argv[0], "sleep") == 0) + if (pg_strcasecmp(my_command->argv[0], "sleep") == 0) { if (my_command->argc < 2) syntax_error(source, lineno, my_command->line, my_command->argv[0],