- that it does work:-) I'm not sure what happens by the script selection
process, it should be checked carefully because it was not designed
with allowing a zero weight, and it may depend on its/their positions.
It may already work, but it really needs checking.
Hmmm, it seems ok.
Attached is an updated patch, which:
- I would suggest that a warning is shown when a weight is zero,
something like "warning, script #%d weight is zero, will be ignored".
includes such a warning.
- the documentation should be updated:-)
adds a line about 0 weight in the documentation.
--
Fabien.
diff --git a/doc/src/sgml/ref/pgbench.sgml b/doc/src/sgml/ref/pgbench.sgml
index c6d1454..e31d5ee 100644
--- a/doc/src/sgml/ref/pgbench.sgml
+++ b/doc/src/sgml/ref/pgbench.sgml
@@ -698,6 +698,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
Each script may be given a relative weight specified after a
<literal>@</> so as to change its drawing probability.
The default weight is <literal>1</>.
+ Weight <literal>0</> scripts are ignored.
</para>
<para>
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 4196b0e..0c1a0ee 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2953,10 +2953,10 @@ parseScriptWeight(const char *option, char **script)
fprintf(stderr, "invalid weight specification: %s\n", sep);
exit(1);
}
- if (wtmp > INT_MAX || wtmp <= 0)
+ if (wtmp > INT_MAX || wtmp < 0)
{
fprintf(stderr,
- "weight specification out of range (1 .. %u): " INT64_FORMAT "\n",
+ "weight specification out of range (0 .. %u): " INT64_FORMAT "\n",
INT_MAX, (int64) wtmp);
exit(1);
}
@@ -2987,6 +2987,13 @@ addScript(ParsedScript script)
exit(1);
}
+ if (script.weight == 0)
+ {
+ fprintf(stderr,
+ "warning, script \"%s\" (%d) weight is zero, will be ignored\n",
+ script.desc, num_scripts);
+ }
+
sql_script[num_scripts] = script;
num_scripts++;
}
@@ -3527,6 +3534,12 @@ main(int argc, char **argv)
/* cannot overflow: weight is 32b, total_weight 64b */
total_weight += sql_script[i].weight;
+ if (total_weight == 0)
+ {
+ fprintf(stderr, "total weight for scripts (-b and -f options) cannot be zero\n");
+ exit(1);
+ }
+
/* show per script stats if several scripts are used */
if (num_scripts > 1)
per_script_stats = true;
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers