4
4
* A simple benchmark program for PostgreSQL
5
5
* Originally written by Tatsuo Ishii and enhanced by many contributors.
6
6
*
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 $
8
8
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
9
9
* ALL RIGHTS RESERVED;
10
10
*
@@ -1449,6 +1449,7 @@ main(int argc, char **argv)
1449
1449
int ttype = 0 ; /* transaction type. 0: TPC-B, 1: SELECT only,
1450
1450
* 2: skip update of branches and tellers */
1451
1451
char * filename = NULL ;
1452
+ bool scale_given = false;
1452
1453
1453
1454
CState * state ; /* status of clients */
1454
1455
@@ -1552,6 +1553,7 @@ main(int argc, char **argv)
1552
1553
is_connect = 1 ;
1553
1554
break ;
1554
1555
case 's' :
1556
+ scale_given = true;
1555
1557
scale = atoi (optarg );
1556
1558
if (scale <= 0 )
1557
1559
{
@@ -1647,16 +1649,6 @@ main(int argc, char **argv)
1647
1649
1648
1650
remains = nclients ;
1649
1651
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
-
1660
1652
if (nclients > 1 )
1661
1653
{
1662
1654
state = (CState * ) realloc (state , sizeof (CState ) * nclients );
@@ -1668,8 +1660,7 @@ main(int argc, char **argv)
1668
1660
1669
1661
memset (state + 1 , 0 , sizeof (* state ) * (nclients - 1 ));
1670
1662
1671
- snprintf (val , sizeof (val ), "%d" , scale );
1672
-
1663
+ /* copy any -D switch values to all clients */
1673
1664
for (i = 1 ; i < nclients ; i ++ )
1674
1665
{
1675
1666
int j ;
@@ -1682,12 +1673,6 @@ main(int argc, char **argv)
1682
1673
exit (1 );
1683
1674
}
1684
1675
}
1685
-
1686
- if (putVariable (& state [i ], "scale" , val ) == false)
1687
- {
1688
- fprintf (stderr , "Couldn't allocate memory for variable\n" );
1689
- exit (1 );
1690
- }
1691
1676
}
1692
1677
}
1693
1678
@@ -1743,22 +1728,26 @@ main(int argc, char **argv)
1743
1728
}
1744
1729
PQclear (res );
1745
1730
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
+ }
1752
1737
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 ++ )
1754
1746
{
1755
- for ( i = 1 ; i < nclients ; i ++ )
1747
+ if ( putVariable ( & state [ i ], "scale" , val ) == false )
1756
1748
{
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 );
1762
1751
}
1763
1752
}
1764
1753
}
0 commit comments