Skip to content

Commit 8f21156

Browse files
committed
Merge remote-tracking branch 'github/master' into uniq-arbiter
2 parents 692c2ed + 3ed261b commit 8f21156

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

src/bin/insbench/insbench.cpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <pqxx/transaction>
1515
#include <pqxx/nontransaction>
1616
#include <pqxx/pipeline>
17+
#include <pqxx/tablewriter>
1718
#include <pqxx/version>
1819

1920
using namespace std;
@@ -44,6 +45,7 @@ struct config
4445
int initialSize;
4546
bool useSystemTime;
4647
bool noPK;
48+
bool useCopy;
4749
string connection;
4850

4951
config() {
@@ -55,6 +57,7 @@ struct config
5557
transactionSize = 100;
5658
useSystemTime = false;
5759
noPK = false;
60+
useCopy = false;
5861
}
5962
};
6063

@@ -105,10 +108,25 @@ void* inserter(void* arg)
105108
work txn(con);
106109
if (cfg.useSystemTime)
107110
{
108-
for (int j = 0; j < cfg.transactionSize; j++)
109-
{
110-
txn.prepared("insert")(getCurrentTime())(random())(random())(random())(random())(random())(random())(random())(random()).exec();
111-
}
111+
if (cfg.useCopy)
112+
{
113+
tablewriter writer(txn,"t");
114+
vector<int64_t> row(9);
115+
for (int j = 0; j < cfg.transactionSize; j++)
116+
{
117+
row[0] = getCurrentTime();
118+
for (int c = 1; c <= 8; c++) {
119+
row[c] = random();
120+
}
121+
writer << row;
122+
}
123+
writer.complete();
124+
} else {
125+
for (int j = 0; j < cfg.transactionSize; j++)
126+
{
127+
txn.prepared("insert")(getCurrentTime())(random())(random())(random())(random())(random())(random())(random())(random()).exec();
128+
}
129+
}
112130
} else {
113131
txn.prepared("insert")(curr)(curr+cfg.transactionSize-1).exec();
114132
curr += cfg.transactionSize;
@@ -167,9 +185,23 @@ void initializeDatabase()
167185
}
168186
if (cfg.useSystemTime)
169187
{
170-
for (int i = 0; i < cfg.initialSize; i++)
171-
{
172-
txn.prepared("insert")(getCurrentTime())(random())(random())(random())(random())(random())(random())(random())(random()).exec();
188+
if (cfg.useCopy) {
189+
tablewriter writer(txn,"t");
190+
vector<int64_t> row(9);
191+
for (int i = 0; i < cfg.initialSize; i++)
192+
{
193+
row[0] = getCurrentTime();
194+
for (int c = 1; c <= 8; c++) {
195+
row[c] = random();
196+
}
197+
writer << row;
198+
}
199+
writer.complete();
200+
} else {
201+
for (int i = 0; i < cfg.initialSize; i++)
202+
{
203+
txn.prepared("insert")(getCurrentTime())(random())(random())(random())(random())(random())(random())(random())(random()).exec();
204+
}
173205
}
174206
} else {
175207
txn.prepared("insert")(cfg.initialSize)(cfg.initialSize-1).exec();
@@ -235,6 +267,9 @@ int main (int argc, char* argv[])
235267
case 'p':
236268
cfg.noPK = true;
237269
continue;
270+
case 'C':
271+
cfg.useCopy = true;
272+
continue;
238273
}
239274
}
240275
printf("Options:\n"
@@ -246,6 +281,7 @@ int main (int argc, char* argv[])
246281
"\t-i N\tinitial table size (1000000)\n"
247282
"\t-q\tuse system time and libpq\n"
248283
"\t-p\tno primary key\n"
284+
"\t-C\tuse COPY command\n"
249285
"\t-c STR\tdatabase connection string\n");
250286
return 1;
251287
}

src/bin/insbench/run.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
echo Insert with 1 index
2-
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -x 0
2+
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -q -C -x 0
33
echo Insert with 9 indexex
4-
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -x 8
5-
echo Insert with 9 partial indexes
6-
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -x 8 -u 1
4+
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -q -C -x 8
5+
echo Insert with 9 concurrently update partial indexes
6+
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -q -C -x 8 -u 1
7+
echo Insert with 9 frozen partial indexes
8+
./insbench -c "dbname=postgres host=localhost port=5432 sslmode=disable" -q -C -x 8 -u 100

0 commit comments

Comments
 (0)