@@ -98,7 +98,8 @@ void* inserter(void* arg)
98
98
} else {
99
99
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))" );
100
100
}
101
-
101
+ time_t curr = currTimestamp;
102
+
102
103
for (int i = 0 ; i < cfg.nIterations ; i++)
103
104
{
104
105
work txn (con);
@@ -109,8 +110,9 @@ void* inserter(void* arg)
109
110
txn.prepared (" insert" )(getCurrentTime ())(random ())(random ())(random ())(random ())(random ())(random ())(random ())(random ()).exec ();
110
111
}
111
112
} 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;
114
116
}
115
117
txn.commit ();
116
118
}
@@ -124,10 +126,11 @@ void* indexUpdater(void* arg)
124
126
sleep (cfg.indexUpdateInterval );
125
127
printf (" Alter indexes\n " );
126
128
time_t now = getCurrentTime ();
129
+ time_t limit = cfg.useSystemTime ? now : currTimestamp;
127
130
{
128
131
work txn (con);
129
132
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 );
131
134
}
132
135
txn.commit ();
133
136
}
@@ -149,18 +152,6 @@ void initializeDatabase()
149
152
time_t now = getCurrentTime ();
150
153
exec (txn, " drop table if exists t" );
151
154
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
- }
164
155
165
156
if (cfg.initialSize )
166
157
{
@@ -184,9 +175,26 @@ void initializeDatabase()
184
175
txn.prepared (" insert" )(cfg.initialSize )(cfg.initialSize -1 ).exec ();
185
176
currTimestamp = cfg.initialSize ;
186
177
}
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
+ }
188
190
}
189
191
txn.commit ();
192
+ {
193
+ nontransaction txn (con);
194
+ txn.exec (" vacuum analyze" );
195
+ sleep (2 );
196
+ }
197
+ printf (" Database intialized\n " );
190
198
}
191
199
192
200
@@ -234,7 +242,8 @@ int main (int argc, char* argv[])
234
242
" \t -w N\t number of inserters (1)\n "
235
243
" \t -u N\t index update interval (0)\n "
236
244
" \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 "
238
247
" \t -q\t use system time and libpq\n "
239
248
" \t -p\t no primary key\n "
240
249
" \t -c STR\t database connection string\n " );
@@ -257,10 +266,11 @@ int main (int argc, char* argv[])
257
266
for (int i = 0 ; i < cfg.nInserters ; i++) {
258
267
inserters[i].wait ();
259
268
}
269
+ time_t elapsed = getCurrentTime () - start;
270
+
260
271
running = false ;
261
272
bgw.wait ();
262
273
263
- time_t elapsed = getCurrentTime () - start;
264
274
265
275
printf (
266
276
" {\" tps\" :%f, \" index_updates\" :%d, \" max_update_time\" :%ld, \" avg_update_time\" :%f,"
0 commit comments