@@ -98,7 +98,8 @@ void* inserter(void* arg)
9898 } else {
9999 con.prepare (" insert" , " insert into t (select generate_series($1::integer,$2::integer),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000),ceil(random()*1000000000))" );
100100 }
101-
101+ time_t curr = currTimestamp;
102+
102103 for (int i = 0 ; i < cfg.nIterations ; i++)
103104 {
104105 work txn (con);
@@ -109,8 +110,9 @@ void* inserter(void* arg)
109110 txn.prepared (" insert" )(getCurrentTime ())(random ())(random ())(random ())(random ())(random ())(random ())(random ())(random ()).exec ();
110111 }
111112 } else {
112- currTimestamp = i*cfg.transactionSize ;
113- txn.prepared (" insert" )(i*cfg.transactionSize )((i+1 )*cfg.transactionSize -1 ).exec ();
113+ txn.prepared (" insert" )(curr)(curr+cfg.transactionSize -1 ).exec ();
114+ curr += cfg.transactionSize ;
115+ currTimestamp = curr;
114116 }
115117 txn.commit ();
116118 }
@@ -124,10 +126,11 @@ void* indexUpdater(void* arg)
124126 sleep (cfg.indexUpdateInterval );
125127 printf (" Alter indexes\n " );
126128 time_t now = getCurrentTime ();
129+ time_t limit = cfg.useSystemTime ? now : currTimestamp;
127130 {
128131 work txn (con);
129132 for (int i = 0 ; i < cfg.nIndexes ; i++) {
130- exec (txn, " alter index idx%d where pk<%lu" , i, cfg. useSystemTime ? now : currTimestamp );
133+ exec (txn, " alter index idx%d where pk<%lu" , i, limit );
131134 }
132135 txn.commit ();
133136 }
@@ -149,18 +152,6 @@ void initializeDatabase()
149152 time_t now = getCurrentTime ();
150153 exec (txn, " drop table if exists t" );
151154 exec (txn, " create table t (pk bigint, k1 bigint, k2 bigint, k3 bigint, k4 bigint, k5 bigint, k6 bigint, k7 bigint, k8 bigint)" );
152- if (!cfg.noPK ) {
153- exec (txn, " create index pk on t(pk)" );
154- }
155- for (int i = 0 ; i < cfg.nIndexes ; i++) {
156- if (cfg.indexUpdateInterval == 0 ) {
157- exec (txn, " create index idx%d on t(k%d)" , i, i+1 );
158- } else if (cfg.useSystemTime ) {
159- exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , now);
160- } else {
161- exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , 0 );
162- }
163- }
164155
165156 if (cfg.initialSize )
166157 {
@@ -184,9 +175,26 @@ void initializeDatabase()
184175 txn.prepared (" insert" )(cfg.initialSize )(cfg.initialSize -1 ).exec ();
185176 currTimestamp = cfg.initialSize ;
186177 }
187- txn.exec (" vacuum analyze" );
178+ }
179+ if (!cfg.noPK ) {
180+ exec (txn, " create index pk on t(pk)" );
181+ }
182+ for (int i = 0 ; i < cfg.nIndexes ; i++) {
183+ if (cfg.indexUpdateInterval == 0 ) {
184+ exec (txn, " create index idx%d on t(k%d)" , i, i+1 );
185+ } else if (cfg.useSystemTime ) {
186+ exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , now);
187+ } else {
188+ exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , currTimestamp);
189+ }
188190 }
189191 txn.commit ();
192+ {
193+ nontransaction txn (con);
194+ txn.exec (" vacuum analyze" );
195+ sleep (2 );
196+ }
197+ printf (" Database intialized\n " );
190198}
191199
192200
@@ -234,7 +242,8 @@ int main (int argc, char* argv[])
234242 " \t -w N\t number of inserters (1)\n "
235243 " \t -u N\t index update interval (0)\n "
236244 " \t -n N\t number of iterations (10000)\n "
237- " \t -i N\t number of indexes (8)\n "
245+ " \t -x N\t number of indexes (8)\n "
246+ " \t -i N\t initial table size (1000000)\n "
238247 " \t -q\t use system time and libpq\n "
239248 " \t -p\t no primary key\n "
240249 " \t -c STR\t database connection string\n " );
@@ -257,10 +266,11 @@ int main (int argc, char* argv[])
257266 for (int i = 0 ; i < cfg.nInserters ; i++) {
258267 inserters[i].wait ();
259268 }
269+ time_t elapsed = getCurrentTime () - start;
270+
260271 running = false ;
261272 bgw.wait ();
262273
263- time_t elapsed = getCurrentTime () - start;
264274
265275 printf (
266276 " {\" tps\" :%f, \" index_updates\" :%d, \" max_update_time\" :%ld, \" avg_update_time\" :%f,"
0 commit comments