11/*
2- * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.15 2002/02/18 05:46:41 momjian Exp $
2+ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.16 2002/02/24 00:17:57 ishii Exp $
33 *
44 * pgbench: a simple TPC-B like benchmark program for PostgreSQL
55 * written by Tatsuo Ishii
66 *
7- * Copyright (c) 2000 Tatsuo Ishii
7+ * Copyright (c) 2000-2002 Tatsuo Ishii
88 *
99 * Permission to use, copy, modify, and distribute this software and
1010 * its documentation for any purpose and without fee is hereby
@@ -95,7 +95,7 @@ typedef struct
9595static void
9696usage ()
9797{
98- fprintf (stderr ,"usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-U login][-P password][-d][dbname]\n" );
98+ fprintf (stderr ,"usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-N][- U login][-P password][-d][dbname]\n" );
9999fprintf (stderr ,"(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-U login][-P password][-d][dbname]\n" );
100100}
101101
@@ -168,7 +168,7 @@ check(CState * state, PGresult *res, int n, int good)
168168
169169/* process a transaction */
170170static void
171- doOne (CState * state ,int n ,int debug )
171+ doOne (CState * state ,int n ,int debug , int ttype )
172172{
173173char sql [256 ];
174174PGresult * res ;
@@ -295,12 +295,18 @@ doOne(CState * state, int n, int debug)
295295sprintf (sql ,"select abalance from accounts where aid = %d" ,st -> aid );
296296break ;
297297case 3 :
298- sprintf (sql ,"update tellers set tbalance = tbalance + %d where tid = %d\n" ,
299- st -> delta ,st -> tid );
300- break ;
298+ if (ttype == 0 )
299+ {
300+ sprintf (sql ,"update tellers set tbalance = tbalance + %d where tid = %d\n" ,
301+ st -> delta ,st -> tid );
302+ break ;
303+ }
301304case 4 :
302- sprintf (sql ,"update branches set bbalance = bbalance + %d where bid = %d" ,st -> delta ,st -> bid );
303- break ;
305+ if (ttype == 0 )
306+ {
307+ sprintf (sql ,"update branches set bbalance = bbalance + %d where bid = %d" ,st -> delta ,st -> bid );
308+ break ;
309+ }
304310case 5 :
305311sprintf (sql ,"insert into history(tid,bid,aid,delta,mtime) values(%d,%d,%d,%d,'now')" ,
306312st -> tid ,st -> bid ,st -> aid ,st -> delta );
@@ -548,6 +554,18 @@ init()
548554fprintf (stderr ,"PQendcopy failed\n" );
549555exit (1 );
550556}
557+
558+ #ifdef NOT_USED
559+ /*
560+ * do a checkpoint to purge the old WAL logs
561+ */
562+ res = PQexec (con ,"checkpoint" );
563+ if (PQresultStatus (res )!= PGRES_COMMAND_OK )
564+ {
565+ fprintf (stderr ,"%s" ,PQerrorMessage (con ));
566+ exit (1 );
567+ }
568+ #endif /* NOT_USED */
551569}
552570}
553571
@@ -575,6 +593,7 @@ printResults(
575593t2 ;
576594int i ;
577595int normal_xacts = 0 ;
596+ char * s ;
578597
579598for (i = 0 ;i < nclients ;i ++ )
580599normal_xacts += state [i ].cnt ;
@@ -585,7 +604,14 @@ printResults(
585604t2 = (tv3 -> tv_sec - tv2 -> tv_sec )* 1000000.0 + (tv3 -> tv_usec - tv2 -> tv_usec );
586605t2 = normal_xacts * 1000000.0 /t2 ;
587606
588- printf ("transaction type: %s\n" ,ttype == 0 ?"TPC-B (sort of)" :"SELECT only" );
607+ if (ttype == 0 )
608+ s = "TPC-B (sort of)" ;
609+ else if (ttype == 2 )
610+ s = "Update only accounts" ;
611+ else
612+ s = "SELECT only" ;
613+
614+ printf ("transaction type: %s\n" ,s );
589615printf ("scaling factor: %d\n" ,tps );
590616printf ("number of clients: %d\n" ,nclients );
591617printf ("number of transactions per client: %d\n" ,nxacts );
@@ -609,7 +635,8 @@ main(int argc, char **argv)
609635int is_full_vacuum = 0 ;/* do full vacuum before testing? */
610636int debug = 0 ;/* debug flag */
611637int ttype = 0 ;/* transaction type. 0: TPC-B, 1: SELECT
612- * only */
638+ * only
639+ 2: skip updation of branches and tellers */
613640
614641static CState state [MAXCLIENTS ];/* clients status */
615642
@@ -631,7 +658,7 @@ main(int argc, char **argv)
631658PGconn * con ;
632659PGresult * res ;
633660
634- while ((c = getopt (argc ,argv ,"ih:nvp:dc:t:s:U:P:CS " ))!= -1 )
661+ while ((c = getopt (argc ,argv ,"ih:nvp:dc:t:s:U:P:CNS " ))!= -1 )
635662{
636663switch (c )
637664{
@@ -656,6 +683,9 @@ main(int argc, char **argv)
656683case 'S' :
657684ttype = 1 ;
658685break ;
686+ case 'N' :
687+ ttype = 2 ;
688+ break ;
659689case 'c' :
660690nclients = atoi (optarg );
661691if (nclients <=0 || nclients > MAXCLIENTS )
@@ -841,8 +871,8 @@ main(int argc, char **argv)
841871/* send start up quries in async manner */
842872for (i = 0 ;i < nclients ;i ++ )
843873{
844- if (ttype == 0 )
845- doOne (state ,i ,debug );
874+ if (ttype == 0 || ttype == 2 )
875+ doOne (state ,i ,debug , ttype );
846876else if (ttype == 1 )
847877doSelectOnly (state ,i ,debug );
848878}
@@ -905,8 +935,8 @@ main(int argc, char **argv)
905935{
906936if (state [i ].con && FD_ISSET (PQsocket (state [i ].con ),& input_mask ))
907937{
908- if (ttype == 0 )
909- doOne (state ,i ,debug );
938+ if (ttype == 0 || ttype == 2 )
939+ doOne (state ,i ,debug , ttype );
910940else if (ttype == 1 )
911941doSelectOnly (state ,i ,debug );
912942}