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)
14491449int ttype = 0 ;/* transaction type. 0: TPC-B, 1: SELECT only,
14501450 * 2: skip update of branches and tellers */
14511451char * filename = NULL ;
1452+ bool scale_given = false;
14521453
14531454CState * state ;/* status of clients */
14541455
@@ -1552,6 +1553,7 @@ main(int argc, char **argv)
15521553is_connect = 1 ;
15531554break ;
15541555case 's' :
1556+ scale_given = true;
15551557scale = atoi (optarg );
15561558if (scale <=0 )
15571559{
@@ -1647,16 +1649,6 @@ main(int argc, char **argv)
16471649
16481650remains = 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-
16601652if (nclients > 1 )
16611653{
16621654state = (CState * )realloc (state ,sizeof (CState )* nclients );
@@ -1668,8 +1660,7 @@ main(int argc, char **argv)
16681660
16691661memset (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 */
16731664for (i = 1 ;i < nclients ;i ++ )
16741665{
16751666int j ;
@@ -1682,12 +1673,6 @@ main(int argc, char **argv)
16821673exit (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}
17441729PQclear (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}