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.85 2009/02/27 09:30:21 petere Exp $
7+ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.86 2009/05/07 22:01:18 tgl Exp $
88 * Copyright (c) 2000-2009, PostgreSQL Global Development Group
99 * ALL RIGHTS RESERVED;
1010 *
@@ -76,8 +76,8 @@ intnxacts = 0;/* number of transactions per client */
7676int duration = 0 ;/* duration in seconds */
7777
7878/*
79- * scaling factor. for example, scale = 10 will make 1000000 tuplesof
80- *accounts table.
79+ * scaling factor. for example, scale = 10 will make 1000000 tuplesin
80+ *pgbench_accounts table.
8181 */
8282int scale = 1 ;
8383
@@ -181,11 +181,11 @@ static char *tpc_b = {
181181"\\setrandom tid 1 :ntellers\n"
182182"\\setrandom delta -5000 5000\n"
183183"BEGIN;\n"
184- "UPDATEaccounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
185- "SELECT abalance FROMaccounts WHERE aid = :aid;\n"
186- "UPDATEtellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
187- "UPDATEbranches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
188- "INSERT INTOhistory (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
184+ "UPDATEpgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
185+ "SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
186+ "UPDATEpgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
187+ "UPDATEpgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
188+ "INSERT INTOpgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
189189"END;\n"
190190};
191191
@@ -199,17 +199,17 @@ static char *simple_update = {
199199"\\setrandom tid 1 :ntellers\n"
200200"\\setrandom delta -5000 5000\n"
201201"BEGIN;\n"
202- "UPDATEaccounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
203- "SELECT abalance FROMaccounts WHERE aid = :aid;\n"
204- "INSERT INTOhistory (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
202+ "UPDATEpgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
203+ "SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
204+ "INSERT INTOpgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
205205"END;\n"
206206};
207207
208208/* -S case */
209209static char * select_only = {
210210"\\set naccounts 100000 * :scale\n"
211211"\\setrandom aid 1 :naccounts\n"
212- "SELECT abalance FROMaccounts WHERE aid = :aid;\n"
212+ "SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
213213};
214214
215215/* Connection overhead time */
@@ -269,8 +269,8 @@ usage(const char *progname)
269269" -M {simple|extended|prepared}\n"
270270" protocol for submitting queries to server (default: simple)\n"
271271" -n do not run VACUUM before tests\n"
272- " -N do not update tables \"tellers \" and \"branches \"\n"
273- " -s NUM report scale factor in output\n"
272+ " -N do not update tables \"pgbench_tellers \" and \"pgbench_branches \"\n"
273+ " -s NUM reportthis scale factor in output\n"
274274" -S perform SELECT-only transactions\n"
275275" -t NUM number of transactions each client runs (default: 10)\n"
276276" -T NUM duration of benchmark test in seconds\n"
@@ -357,8 +357,6 @@ doConnect(void)
357357return NULL ;
358358}
359359
360- executeStatement (conn ,"SET search_path = public" );
361-
362360return conn ;
363361}
364362
@@ -1001,8 +999,6 @@ disconnect_all(CState * state)
1001999static void
10021000init (void )
10031001{
1004- PGconn * con ;
1005- PGresult * res ;
10061002/*
10071003 * Note: TPC-B requires at least 100 bytes per row, and the "filler"
10081004 * fields in these table declarations were intended to comply with that.
@@ -1014,22 +1010,24 @@ init(void)
10141010 * behavior.
10151011 */
10161012static char * DDLs []= {
1017- "drop table if exists branches" ,
1018- "create table branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)" ,
1019- "drop table if exists tellers" ,
1020- "create table tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)" ,
1021- "drop table if exists accounts" ,
1022- "create table accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)" ,
1023- "drop table if exists history" ,
1024- "create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))" };
1013+ "drop table if exists pgbench_branches" ,
1014+ "create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)" ,
1015+ "drop table if exists pgbench_tellers" ,
1016+ "create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)" ,
1017+ "drop table if exists pgbench_accounts" ,
1018+ "create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)" ,
1019+ "drop table if exists pgbench_history" ,
1020+ "create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"
1021+ };
10251022static char * DDLAFTERs []= {
1026- "alter tablebranches add primary key (bid)" ,
1027- "alter tabletellers add primary key (tid)" ,
1028- "alter tableaccounts add primary key (aid)" };
1029-
1023+ "alter tablepgbench_branches add primary key (bid)" ,
1024+ "alter tablepgbench_tellers add primary key (tid)" ,
1025+ "alter tablepgbench_accounts add primary key (aid)"
1026+ };
10301027
1028+ PGconn * con ;
1029+ PGresult * res ;
10311030char sql [256 ];
1032-
10331031int i ;
10341032
10351033if ((con = doConnect ())== NULL )
@@ -1040,9 +1038,9 @@ init(void)
10401038/*
10411039 * set fillfactor for branches, tellers and accounts tables
10421040 */
1043- if ((strstr (DDLs [i ],"create tablebranches " )== DDLs [i ])||
1044- (strstr (DDLs [i ],"create tabletellers " )== DDLs [i ])||
1045- (strstr (DDLs [i ],"create tableaccounts " )== DDLs [i ]))
1041+ if ((strstr (DDLs [i ],"create tablepgbench_branches " )== DDLs [i ])||
1042+ (strstr (DDLs [i ],"create tablepgbench_tellers " )== DDLs [i ])||
1043+ (strstr (DDLs [i ],"create tablepgbench_accounts " )== DDLs [i ]))
10461044{
10471045char ddl_stmt [128 ];
10481046
@@ -1058,28 +1056,28 @@ init(void)
10581056
10591057for (i = 0 ;i < nbranches * scale ;i ++ )
10601058{
1061- snprintf (sql ,256 ,"insert intobranches (bid,bbalance) values(%d,0)" ,i + 1 );
1059+ snprintf (sql ,256 ,"insert intopgbench_branches (bid,bbalance) values(%d,0)" ,i + 1 );
10621060executeStatement (con ,sql );
10631061}
10641062
10651063for (i = 0 ;i < ntellers * scale ;i ++ )
10661064{
1067- snprintf (sql ,256 ,"insert intotellers (tid,bid,tbalance) values (%d,%d,0)"
1065+ snprintf (sql ,256 ,"insert intopgbench_tellers (tid,bid,tbalance) values (%d,%d,0)"
10681066 ,i + 1 ,i /ntellers + 1 );
10691067executeStatement (con ,sql );
10701068}
10711069
10721070executeStatement (con ,"commit" );
10731071
10741072/*
1075- * fill theaccounts table with some data
1073+ * fill thepgbench_accounts table with some data
10761074 */
10771075fprintf (stderr ,"creating tables...\n" );
10781076
10791077executeStatement (con ,"begin" );
1080- executeStatement (con ,"truncateaccounts " );
1078+ executeStatement (con ,"truncatepgbench_accounts " );
10811079
1082- res = PQexec (con ,"copyaccounts from stdin" );
1080+ res = PQexec (con ,"copypgbench_accounts from stdin" );
10831081if (PQresultStatus (res )!= PGRES_COPY_IN )
10841082{
10851083fprintf (stderr ,"%s" ,PQerrorMessage (con ));
@@ -1122,10 +1120,10 @@ init(void)
11221120
11231121/* vacuum */
11241122fprintf (stderr ,"vacuum..." );
1125- executeStatement (con ,"vacuum analyzebranches " );
1126- executeStatement (con ,"vacuum analyzetellers " );
1127- executeStatement (con ,"vacuum analyzeaccounts " );
1128- executeStatement (con ,"vacuum analyzehistory " );
1123+ executeStatement (con ,"vacuum analyzepgbench_branches " );
1124+ executeStatement (con ,"vacuum analyzepgbench_tellers " );
1125+ executeStatement (con ,"vacuum analyzepgbench_accounts " );
1126+ executeStatement (con ,"vacuum analyzepgbench_history " );
11291127
11301128fprintf (stderr ,"done.\n" );
11311129PQfinish (con );
@@ -1466,7 +1464,7 @@ printResults(
14661464if (ttype == 0 )
14671465s = "TPC-B (sort of)" ;
14681466else if (ttype == 2 )
1469- s = "Update onlyaccounts " ;
1467+ s = "Update onlypgbench_accounts " ;
14701468else if (ttype == 1 )
14711469s = "SELECT only" ;
14721470else
@@ -1811,9 +1809,9 @@ main(int argc, char **argv)
18111809{
18121810/*
18131811 * get the scaling factor that should be same as count(*) from
1814- *branches if this is not a custom query
1812+ *pgbench_branches if this is not a custom query
18151813 */
1816- res = PQexec (con ,"select count(*) frombranches " );
1814+ res = PQexec (con ,"select count(*) frompgbench_branches " );
18171815if (PQresultStatus (res )!= PGRES_TUPLES_OK )
18181816{
18191817fprintf (stderr ,"%s" ,PQerrorMessage (con ));
@@ -1822,15 +1820,15 @@ main(int argc, char **argv)
18221820scale = atoi (PQgetvalue (res ,0 ,0 ));
18231821if (scale < 0 )
18241822{
1825- fprintf (stderr ,"count(*) frombranches invalid (%d)\n" ,scale );
1823+ fprintf (stderr ,"count(*) frompgbench_branches invalid (%d)\n" ,scale );
18261824exit (1 );
18271825}
18281826PQclear (res );
18291827
18301828/* warn if we override user-given -s switch */
18311829if (scale_given )
18321830fprintf (stderr ,
1833- "Scale option ignored, usingbranches table count = %d\n" ,
1831+ "Scale option ignored, usingpgbench_branches table count = %d\n" ,
18341832scale );
18351833}
18361834
@@ -1854,15 +1852,15 @@ main(int argc, char **argv)
18541852if (!is_no_vacuum )
18551853{
18561854fprintf (stderr ,"starting vacuum..." );
1857- executeStatement (con ,"vacuumbranches " );
1858- executeStatement (con ,"vacuumtellers " );
1859- executeStatement (con ,"truncatehistory " );
1855+ executeStatement (con ,"vacuumpgbench_branches " );
1856+ executeStatement (con ,"vacuumpgbench_tellers " );
1857+ executeStatement (con ,"truncatepgbench_history " );
18601858fprintf (stderr ,"end.\n" );
18611859
18621860if (do_vacuum_accounts )
18631861{
1864- fprintf (stderr ,"starting vacuumaccounts ..." );
1865- executeStatement (con ,"vacuum analyzeaccounts " );
1862+ fprintf (stderr ,"starting vacuumpgbench_accounts ..." );
1863+ executeStatement (con ,"vacuum analyzepgbench_accounts " );
18661864fprintf (stderr ,"end.\n" );
18671865}
18681866}