From 6b1b4641b8d6dabe4815dcc3406a63ac3b777933 Mon Sep 17 00:00:00 2001 From: Tom Lane <tgl@sss.pgh.pa.us> Date: Fri, 9 May 2008 15:53:07 +0000 Subject: [PATCH] Give a warning if -s switch is used with a non-custom pgbench test. Also, clean up the code that assigned the scale into :scale variables. Greg Smith and Tom Lane --- contrib/pgbench/pgbench.c | 53 ++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 41312e88c64..cfa6c5fb89b 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -4,7 +4,7 @@ * A simple benchmark program for PostgreSQL * Originally written by Tatsuo Ishii and enhanced by many contributors. * - * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.79 2008/03/19 03:33:21 ishii Exp $ + * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.80 2008/05/09 15:53:07 tgl Exp $ * Copyright (c) 2000-2008, PostgreSQL Global Development Group * ALL RIGHTS RESERVED; * @@ -1449,6 +1449,7 @@ main(int argc, char **argv) int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only, * 2: skip update of branches and tellers */ char *filename = NULL; + bool scale_given = false; CState *state; /* status of clients */ @@ -1552,6 +1553,7 @@ main(int argc, char **argv) is_connect = 1; break; case 's': + scale_given = true; scale = atoi(optarg); if (scale <= 0) { @@ -1647,16 +1649,6 @@ main(int argc, char **argv) remains = nclients; - if (getVariable(&state[0], "scale") == NULL) - { - snprintf(val, sizeof(val), "%d", scale); - if (putVariable(&state[0], "scale", val) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); - exit(1); - } - } - if (nclients > 1) { state = (CState *) realloc(state, sizeof(CState) * nclients); @@ -1668,8 +1660,7 @@ main(int argc, char **argv) memset(state + 1, 0, sizeof(*state) * (nclients - 1)); - snprintf(val, sizeof(val), "%d", scale); - + /* copy any -D switch values to all clients */ for (i = 1; i < nclients; i++) { int j; @@ -1682,12 +1673,6 @@ main(int argc, char **argv) exit(1); } } - - if (putVariable(&state[i], "scale", val) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); - exit(1); - } } } @@ -1743,22 +1728,26 @@ main(int argc, char **argv) } PQclear(res); - snprintf(val, sizeof(val), "%d", scale); - if (putVariable(&state[0], "scale", val) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); - exit(1); - } + /* warn if we override user-given -s switch */ + if (scale_given) + fprintf(stderr, + "Scale option ignored, using branches table count = %d\n", + scale); + } - if (nclients > 1) + /* + * :scale variables normally get -s or database scale, but don't override + * an explicit -D switch + */ + if (getVariable(&state[0], "scale") == NULL) + { + snprintf(val, sizeof(val), "%d", scale); + for (i = 0; i < nclients; i++) { - for (i = 1; i < nclients; i++) + if (putVariable(&state[i], "scale", val) == false) { - if (putVariable(&state[i], "scale", val) == false) - { - fprintf(stderr, "Couldn't allocate memory for variable\n"); - exit(1); - } + fprintf(stderr, "Couldn't allocate memory for variable\n"); + exit(1); } } } -- GitLab