@@ -126,10 +126,11 @@ void* indexUpdater(void* arg)
126126 sleep (cfg.indexUpdateInterval );
127127 printf (" Alter indexes\n " );
128128 time_t now = getCurrentTime ();
129+ time_t limit = cfg.useSystemTime ? now : currTimestamp;
129130 {
130131 work txn (con);
131132 for (int i = 0 ; i < cfg.nIndexes ; i++) {
132- 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 );
133134 }
134135 txn.commit ();
135136 }
@@ -151,18 +152,6 @@ void initializeDatabase()
151152 time_t now = getCurrentTime ();
152153 exec (txn, " drop table if exists t" );
153154 exec (txn, " create table t (pk bigint, k1 bigint, k2 bigint, k3 bigint, k4 bigint, k5 bigint, k6 bigint, k7 bigint, k8 bigint)" );
154- if (!cfg.noPK ) {
155- exec (txn, " create index pk on t(pk)" );
156- }
157- for (int i = 0 ; i < cfg.nIndexes ; i++) {
158- if (cfg.indexUpdateInterval == 0 ) {
159- exec (txn, " create index idx%d on t(k%d)" , i, i+1 );
160- } else if (cfg.useSystemTime ) {
161- exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , now);
162- } else {
163- exec (txn, " create index idx%d on t(k%d) where pk<%ld" , i, i+1 , 0 );
164- }
165- }
166155
167156 if (cfg.initialSize )
168157 {
@@ -186,9 +175,26 @@ void initializeDatabase()
186175 txn.prepared (" insert" )(cfg.initialSize )(cfg.initialSize -1 ).exec ();
187176 currTimestamp = cfg.initialSize ;
188177 }
189- 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+ }
190190 }
191191 txn.commit ();
192+ {
193+ nontransaction txn (con);
194+ txn.exec (" vacuum analyze" );
195+ sleep (2 );
196+ }
197+ printf (" Database intialized\n " );
192198}
193199
194200
@@ -260,10 +266,11 @@ int main (int argc, char* argv[])
260266 for (int i = 0 ; i < cfg.nInserters ; i++) {
261267 inserters[i].wait ();
262268 }
269+ time_t elapsed = getCurrentTime () - start;
270+
263271 running = false ;
264272 bgw.wait ();
265273
266- time_t elapsed = getCurrentTime () - start;
267274
268275 printf (
269276 " {\" tps\" :%f, \" index_updates\" :%d, \" max_update_time\" :%ld, \" avg_update_time\" :%f,"
0 commit comments