This patch is pretty trivial.
Add modulo operator to pgbench.This is useful to compute a permutation for tests with non uniform accesses (exponential or gaussian), so as to avoid trivial correlations between neighbour keys.
-- Fabien.
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index ad55c3c..16744ac 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -1570,6 +1570,16 @@ top: } snprintf(res, sizeof(res), INT64_FORMAT, ope1 / ope2); } + else if (strcmp(argv[3], "%") == 0) + { + if (ope2 == 0) + { + fprintf(stderr, "%s: division by zero in modulo\n", argv[0]); + st->ecnt++; + return true; + } + snprintf(res, sizeof(res), INT64_FORMAT, ope1 % ope2); + } else { fprintf(stderr, "%s: unsupported operator %s\n", argv[0], argv[3]); diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml index b7d88f3..9a6ee3b 100644 --- a/doc/src/sgml/pgbench.sgml +++ b/doc/src/sgml/pgbench.sgml @@ -735,7 +735,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</> Each <replaceable>operand</> is either an integer constant or a <literal>:</><replaceable>variablename</> reference to a variable having an integer value. The <replaceable>operator</> can be - <literal>+</>, <literal>-</>, <literal>*</>, or <literal>/</>. + <literal>+</>, <literal>-</>, <literal>*</>, <literal>%</> or <literal>/</>. </para> <para>
psql test < pgbench-modulo-test-init.sql ./pgbench -M prepared -f pgbench-modulo-test-run.sql -P 1 -t 100000 -n test psql test < pgbench-modulo-test-check.sql
pgbench-modulo-test-init.sql
Description: application/sql
pgbench-modulo-test-run.sql
Description: application/sql
pgbench-modulo-test-check.sql
Description: application/sql
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers