Skip to content

Commit a1c935d

Browse files
committed
pgbench: allow a script weight of zero
This refines the previous weight range and allows a script to be "turned off" by passing a zero weight, which is useful when scripting multiple pgbench runs. I did not apply the suggested warning when a script uses zero weight; we use the principle elsewhere that if there's nothing to be done, do nothing quietly. Adjust docs accordingly. Author: Jeff Janes, Fabien Coelho
1 parent ad95664 commit a1c935d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

doc/src/sgml/ref/pgbench.sgml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
698698
Each script may be given a relative weight specified after a
699699
<literal>@</> so as to change its drawing probability.
700700
The default weight is <literal>1</>.
701+
Scripts with a weight of <literal>0</> are ignored.
701702
</para>
702703

703704
<para>
@@ -1259,17 +1260,17 @@ tps = 618.764555 (including connections establishing)
12591260
tps = 622.977698 (excluding connections establishing)
12601261
script statistics:
12611262
- statement latencies in milliseconds:
1262-
0.002522 \set aid random(1, 100000 * :scale)
1263-
0.005459 \set bid random(1, 1 * :scale)
1264-
0.002348 \set tid random(1, 10 * :scale)
1265-
0.001078 \set delta random(-5000, 5000)
1266-
0.326152 BEGIN;
1267-
0.603376 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
1268-
0.454643 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
1269-
5.528491 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
1270-
7.335435 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
1271-
0.371851 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
1272-
1.212976 END;
1263+
0.002 \set aid random(1, 100000 * :scale)
1264+
0.005 \set bid random(1, 1 * :scale)
1265+
0.002 \set tid random(1, 10 * :scale)
1266+
0.001 \set delta random(-5000, 5000)
1267+
0.326 BEGIN;
1268+
0.603 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
1269+
0.454 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
1270+
5.528 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
1271+
7.335 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
1272+
0.371 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
1273+
1.212 END;
12731274
</screen>
12741275
</para>
12751276

src/bin/pgbench/pgbench.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,10 +3054,10 @@ parseScriptWeight(const char *option, char **script)
30543054
fprintf(stderr, "invalid weight specification: %s\n", sep);
30553055
exit(1);
30563056
}
3057-
if (wtmp > INT_MAX || wtmp <= 0)
3057+
if (wtmp > INT_MAX || wtmp < 0)
30583058
{
30593059
fprintf(stderr,
3060-
"weight specification out of range (1 .. %u): " INT64_FORMAT "\n",
3060+
"weight specification out of range (0 .. %u): " INT64_FORMAT "\n",
30613061
INT_MAX, (int64) wtmp);
30623062
exit(1);
30633063
}
@@ -3181,10 +3181,11 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
31813181
{
31823182
if (num_scripts > 1)
31833183
printf("SQL script %d: %s\n"
3184-
" - weight = %d\n"
3184+
" - weight = %d (targets %.1f%% of total)\n"
31853185
" - " INT64_FORMAT " transactions (%.1f%% of total, tps = %f)\n",
31863186
i + 1, sql_script[i].desc,
31873187
sql_script[i].weight,
3188+
100.0 * sql_script[i].weight / total_weight,
31883189
sql_script[i].stats.cnt,
31893190
100.0 * sql_script[i].stats.cnt / total->cnt,
31903191
sql_script[i].stats.cnt / time_include);
@@ -3628,6 +3629,12 @@ main(int argc, char **argv)
36283629
/* cannot overflow: weight is 32b, total_weight 64b */
36293630
total_weight += sql_script[i].weight;
36303631

3632+
if (total_weight == 0 && !is_init_mode)
3633+
{
3634+
fprintf(stderr, "total script weight must not be zero\n");
3635+
exit(1);
3636+
}
3637+
36313638
/* show per script stats if several scripts are used */
36323639
if (num_scripts > 1)
36333640
per_script_stats = true;

0 commit comments

Comments
 (0)