Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6b1b464

Browse files
committed
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
1 parent d35c56e commit 6b1b464

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

contrib/pgbench/pgbench.c

+21-32
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A simple benchmark program for PostgreSQL
55
* Originally written by Tatsuo Ishii and enhanced by many contributors.
66
*
7-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.79 2008/03/19 03:33:21 ishii Exp $
7+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.80 2008/05/09 15:53:07 tgl Exp $
88
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
99
* ALL RIGHTS RESERVED;
1010
*
@@ -1449,6 +1449,7 @@ main(int argc, char **argv)
14491449
int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only,
14501450
* 2: skip update of branches and tellers */
14511451
char *filename = NULL;
1452+
bool scale_given = false;
14521453

14531454
CState *state; /* status of clients */
14541455

@@ -1552,6 +1553,7 @@ main(int argc, char **argv)
15521553
is_connect = 1;
15531554
break;
15541555
case 's':
1556+
scale_given = true;
15551557
scale = atoi(optarg);
15561558
if (scale <= 0)
15571559
{
@@ -1647,16 +1649,6 @@ main(int argc, char **argv)
16471649

16481650
remains = nclients;
16491651

1650-
if (getVariable(&state[0], "scale") == NULL)
1651-
{
1652-
snprintf(val, sizeof(val), "%d", scale);
1653-
if (putVariable(&state[0], "scale", val) == false)
1654-
{
1655-
fprintf(stderr, "Couldn't allocate memory for variable\n");
1656-
exit(1);
1657-
}
1658-
}
1659-
16601652
if (nclients > 1)
16611653
{
16621654
state = (CState *) realloc(state, sizeof(CState) * nclients);
@@ -1668,8 +1660,7 @@ main(int argc, char **argv)
16681660

16691661
memset(state + 1, 0, sizeof(*state) * (nclients - 1));
16701662

1671-
snprintf(val, sizeof(val), "%d", scale);
1672-
1663+
/* copy any -D switch values to all clients */
16731664
for (i = 1; i < nclients; i++)
16741665
{
16751666
int j;
@@ -1682,12 +1673,6 @@ main(int argc, char **argv)
16821673
exit(1);
16831674
}
16841675
}
1685-
1686-
if (putVariable(&state[i], "scale", val) == false)
1687-
{
1688-
fprintf(stderr, "Couldn't allocate memory for variable\n");
1689-
exit(1);
1690-
}
16911676
}
16921677
}
16931678

@@ -1743,22 +1728,26 @@ main(int argc, char **argv)
17431728
}
17441729
PQclear(res);
17451730

1746-
snprintf(val, sizeof(val), "%d", scale);
1747-
if (putVariable(&state[0], "scale", val) == false)
1748-
{
1749-
fprintf(stderr, "Couldn't allocate memory for variable\n");
1750-
exit(1);
1751-
}
1731+
/* warn if we override user-given -s switch */
1732+
if (scale_given)
1733+
fprintf(stderr,
1734+
"Scale option ignored, using branches table count = %d\n",
1735+
scale);
1736+
}
17521737

1753-
if (nclients > 1)
1738+
/*
1739+
* :scale variables normally get -s or database scale, but don't override
1740+
* an explicit -D switch
1741+
*/
1742+
if (getVariable(&state[0], "scale") == NULL)
1743+
{
1744+
snprintf(val, sizeof(val), "%d", scale);
1745+
for (i = 0; i < nclients; i++)
17541746
{
1755-
for (i = 1; i < nclients; i++)
1747+
if (putVariable(&state[i], "scale", val) == false)
17561748
{
1757-
if (putVariable(&state[i], "scale", val) == false)
1758-
{
1759-
fprintf(stderr, "Couldn't allocate memory for variable\n");
1760-
exit(1);
1761-
}
1749+
fprintf(stderr, "Couldn't allocate memory for variable\n");
1750+
exit(1);
17621751
}
17631752
}
17641753
}

0 commit comments

Comments
 (0)