Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit48caf91

Browse files
committed
Change pgbench to use the table names pgbench_accounts, pgbench_branches,
pgbench_history, and pgbench_tellers, rather than just accounts, branches,history, and tellers. This is to prevent accidental conflicts with realapplication tables, as has been reported to happen at least once. Alsoremove the automatic "SET search_path = public" that it did at startup,as this seems to restrict testing flexibility without actually buying much.Per proposal by Joshua Drake and ensuing discussion.Joshua Drake and Tom Lane
1 parentfdd48b1 commit48caf91

File tree

2 files changed

+94
-91
lines changed

2 files changed

+94
-91
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A simple benchmark program for PostgreSQL
55
* Originally written by Tatsuo Ishii and enhanced by many contributors.
66
*
7-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.85 2009/02/27 09:30:21 petere Exp $
7+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.86 2009/05/07 22:01:18 tgl Exp $
88
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
99
* ALL RIGHTS RESERVED;
1010
*
@@ -76,8 +76,8 @@ intnxacts = 0;/* number of transactions per client */
7676
intduration=0;/* duration in seconds */
7777

7878
/*
79-
* scaling factor. for example, scale = 10 will make 1000000 tuplesof
80-
*accounts table.
79+
* scaling factor. for example, scale = 10 will make 1000000 tuplesin
80+
*pgbench_accounts table.
8181
*/
8282
intscale=1;
8383

@@ -181,11 +181,11 @@ static char *tpc_b = {
181181
"\\setrandom tid 1 :ntellers\n"
182182
"\\setrandom delta -5000 5000\n"
183183
"BEGIN;\n"
184-
"UPDATEaccounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
185-
"SELECT abalance FROMaccounts WHERE aid = :aid;\n"
186-
"UPDATEtellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
187-
"UPDATEbranches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
188-
"INSERT INTOhistory (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
184+
"UPDATEpgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
185+
"SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
186+
"UPDATEpgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;\n"
187+
"UPDATEpgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;\n"
188+
"INSERT INTOpgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
189189
"END;\n"
190190
};
191191

@@ -199,17 +199,17 @@ static char *simple_update = {
199199
"\\setrandom tid 1 :ntellers\n"
200200
"\\setrandom delta -5000 5000\n"
201201
"BEGIN;\n"
202-
"UPDATEaccounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
203-
"SELECT abalance FROMaccounts WHERE aid = :aid;\n"
204-
"INSERT INTOhistory (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
202+
"UPDATEpgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;\n"
203+
"SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
204+
"INSERT INTOpgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);\n"
205205
"END;\n"
206206
};
207207

208208
/* -S case */
209209
staticchar*select_only= {
210210
"\\set naccounts 100000 * :scale\n"
211211
"\\setrandom aid 1 :naccounts\n"
212-
"SELECT abalance FROMaccounts WHERE aid = :aid;\n"
212+
"SELECT abalance FROMpgbench_accounts WHERE aid = :aid;\n"
213213
};
214214

215215
/* Connection overhead time */
@@ -269,8 +269,8 @@ usage(const char *progname)
269269
" -M {simple|extended|prepared}\n"
270270
" protocol for submitting queries to server (default: simple)\n"
271271
" -n do not run VACUUM before tests\n"
272-
" -N do not update tables \"tellers\" and \"branches\"\n"
273-
" -s NUM report scale factor in output\n"
272+
" -N do not update tables \"pgbench_tellers\" and \"pgbench_branches\"\n"
273+
" -s NUM reportthisscale factor in output\n"
274274
" -S perform SELECT-only transactions\n"
275275
" -t NUM number of transactions each client runs (default: 10)\n"
276276
" -T NUM duration of benchmark test in seconds\n"
@@ -357,8 +357,6 @@ doConnect(void)
357357
returnNULL;
358358
}
359359

360-
executeStatement(conn,"SET search_path = public");
361-
362360
returnconn;
363361
}
364362

@@ -1001,8 +999,6 @@ disconnect_all(CState * state)
1001999
staticvoid
10021000
init(void)
10031001
{
1004-
PGconn*con;
1005-
PGresult*res;
10061002
/*
10071003
* Note: TPC-B requires at least 100 bytes per row, and the "filler"
10081004
* fields in these table declarations were intended to comply with that.
@@ -1014,22 +1010,24 @@ init(void)
10141010
* behavior.
10151011
*/
10161012
staticchar*DDLs[]= {
1017-
"drop table if exists branches",
1018-
"create table branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)",
1019-
"drop table if exists tellers",
1020-
"create table tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)",
1021-
"drop table if exists accounts",
1022-
"create table accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)",
1023-
"drop table if exists history",
1024-
"create table history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"};
1013+
"drop table if exists pgbench_branches",
1014+
"create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=%d)",
1015+
"drop table if exists pgbench_tellers",
1016+
"create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=%d)",
1017+
"drop table if exists pgbench_accounts",
1018+
"create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=%d)",
1019+
"drop table if exists pgbench_history",
1020+
"create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22))"
1021+
};
10251022
staticchar*DDLAFTERs[]= {
1026-
"alter tablebranches add primary key (bid)",
1027-
"alter tabletellers add primary key (tid)",
1028-
"alter tableaccounts add primary key (aid)"};
1029-
1023+
"alter tablepgbench_branches add primary key (bid)",
1024+
"alter tablepgbench_tellers add primary key (tid)",
1025+
"alter tablepgbench_accounts add primary key (aid)"
1026+
};
10301027

1028+
PGconn*con;
1029+
PGresult*res;
10311030
charsql[256];
1032-
10331031
inti;
10341032

10351033
if ((con=doConnect())==NULL)
@@ -1040,9 +1038,9 @@ init(void)
10401038
/*
10411039
* set fillfactor for branches, tellers and accounts tables
10421040
*/
1043-
if ((strstr(DDLs[i],"create tablebranches")==DDLs[i])||
1044-
(strstr(DDLs[i],"create tabletellers")==DDLs[i])||
1045-
(strstr(DDLs[i],"create tableaccounts")==DDLs[i]))
1041+
if ((strstr(DDLs[i],"create tablepgbench_branches")==DDLs[i])||
1042+
(strstr(DDLs[i],"create tablepgbench_tellers")==DDLs[i])||
1043+
(strstr(DDLs[i],"create tablepgbench_accounts")==DDLs[i]))
10461044
{
10471045
charddl_stmt[128];
10481046

@@ -1058,28 +1056,28 @@ init(void)
10581056

10591057
for (i=0;i<nbranches*scale;i++)
10601058
{
1061-
snprintf(sql,256,"insert intobranches(bid,bbalance) values(%d,0)",i+1);
1059+
snprintf(sql,256,"insert intopgbench_branches(bid,bbalance) values(%d,0)",i+1);
10621060
executeStatement(con,sql);
10631061
}
10641062

10651063
for (i=0;i<ntellers*scale;i++)
10661064
{
1067-
snprintf(sql,256,"insert intotellers(tid,bid,tbalance) values (%d,%d,0)"
1065+
snprintf(sql,256,"insert intopgbench_tellers(tid,bid,tbalance) values (%d,%d,0)"
10681066
,i+1,i /ntellers+1);
10691067
executeStatement(con,sql);
10701068
}
10711069

10721070
executeStatement(con,"commit");
10731071

10741072
/*
1075-
* fill theaccounts table with some data
1073+
* fill thepgbench_accounts table with some data
10761074
*/
10771075
fprintf(stderr,"creating tables...\n");
10781076

10791077
executeStatement(con,"begin");
1080-
executeStatement(con,"truncateaccounts");
1078+
executeStatement(con,"truncatepgbench_accounts");
10811079

1082-
res=PQexec(con,"copyaccounts from stdin");
1080+
res=PQexec(con,"copypgbench_accounts from stdin");
10831081
if (PQresultStatus(res)!=PGRES_COPY_IN)
10841082
{
10851083
fprintf(stderr,"%s",PQerrorMessage(con));
@@ -1122,10 +1120,10 @@ init(void)
11221120

11231121
/* vacuum */
11241122
fprintf(stderr,"vacuum...");
1125-
executeStatement(con,"vacuum analyzebranches");
1126-
executeStatement(con,"vacuum analyzetellers");
1127-
executeStatement(con,"vacuum analyzeaccounts");
1128-
executeStatement(con,"vacuum analyzehistory");
1123+
executeStatement(con,"vacuum analyzepgbench_branches");
1124+
executeStatement(con,"vacuum analyzepgbench_tellers");
1125+
executeStatement(con,"vacuum analyzepgbench_accounts");
1126+
executeStatement(con,"vacuum analyzepgbench_history");
11291127

11301128
fprintf(stderr,"done.\n");
11311129
PQfinish(con);
@@ -1466,7 +1464,7 @@ printResults(
14661464
if (ttype==0)
14671465
s="TPC-B (sort of)";
14681466
elseif (ttype==2)
1469-
s="Update onlyaccounts";
1467+
s="Update onlypgbench_accounts";
14701468
elseif (ttype==1)
14711469
s="SELECT only";
14721470
else
@@ -1811,9 +1809,9 @@ main(int argc, char **argv)
18111809
{
18121810
/*
18131811
* get the scaling factor that should be same as count(*) from
1814-
*branches if this is not a custom query
1812+
*pgbench_branches if this is not a custom query
18151813
*/
1816-
res=PQexec(con,"select count(*) frombranches");
1814+
res=PQexec(con,"select count(*) frompgbench_branches");
18171815
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
18181816
{
18191817
fprintf(stderr,"%s",PQerrorMessage(con));
@@ -1822,15 +1820,15 @@ main(int argc, char **argv)
18221820
scale=atoi(PQgetvalue(res,0,0));
18231821
if (scale<0)
18241822
{
1825-
fprintf(stderr,"count(*) frombranches invalid (%d)\n",scale);
1823+
fprintf(stderr,"count(*) frompgbench_branches invalid (%d)\n",scale);
18261824
exit(1);
18271825
}
18281826
PQclear(res);
18291827

18301828
/* warn if we override user-given -s switch */
18311829
if (scale_given)
18321830
fprintf(stderr,
1833-
"Scale option ignored, usingbranches table count = %d\n",
1831+
"Scale option ignored, usingpgbench_branches table count = %d\n",
18341832
scale);
18351833
}
18361834

@@ -1854,15 +1852,15 @@ main(int argc, char **argv)
18541852
if (!is_no_vacuum)
18551853
{
18561854
fprintf(stderr,"starting vacuum...");
1857-
executeStatement(con,"vacuumbranches");
1858-
executeStatement(con,"vacuumtellers");
1859-
executeStatement(con,"truncatehistory");
1855+
executeStatement(con,"vacuumpgbench_branches");
1856+
executeStatement(con,"vacuumpgbench_tellers");
1857+
executeStatement(con,"truncatepgbench_history");
18601858
fprintf(stderr,"end.\n");
18611859

18621860
if (do_vacuum_accounts)
18631861
{
1864-
fprintf(stderr,"starting vacuumaccounts...");
1865-
executeStatement(con,"vacuum analyzeaccounts");
1862+
fprintf(stderr,"starting vacuumpgbench_accounts...");
1863+
executeStatement(con,"vacuum analyzepgbench_accounts");
18661864
fprintf(stderr,"end.\n");
18671865
}
18681866
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp