Commit b1c1aa53 authored by Amit Kapila's avatar Amit Kapila

pgbench: add --partitions and --partition-method options.

These new options allow users to partition the pgbench_accounts table by
specifying the number of partitions and partitioning method.  The values
allowed for partitioning method are range and hash.

This feature allows users to measure the overhead of partitioning if any.

Author: Fabien COELHO
Reviewed-by: Amit Kapila, Amit Langote, Dilip Kumar, Asif Rehman, and
Alvaro Herrera
Discussion: https://postgr.es/m/alpine.DEB.2.21.1907230826190.7008@lancre
parent df86e52c
...@@ -306,6 +306,31 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d ...@@ -306,6 +306,31 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>--partitions=<replaceable>NUM</replaceable></option></term>
<listitem>
<para>
Create a partitioned <literal>pgbench_accounts</literal> table with
<replaceable>NUM</replaceable> partitions of nearly equal size for
the scaled number of accounts.
Default is <literal>0</literal>, meaning no partitioning.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--partition-method=<replaceable>NAME</replaceable></option></term>
<listitem>
<para>
Create a partitioned <literal>pgbench_accounts</literal> table with
<replaceable>NAME</replaceable> method.
Expected values are <literal>range</literal> or <literal>hash</literal>.
This option requires that <option>--partitions</option> is set to non-zero.
If unspecified, default is <literal>range</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>--tablespace=<replaceable>tablespace</replaceable></option></term> <term><option>--tablespace=<replaceable>tablespace</replaceable></option></term>
<listitem> <listitem>
......
This diff is collapsed.
...@@ -58,6 +58,19 @@ sub pgbench ...@@ -58,6 +58,19 @@ sub pgbench
return; return;
} }
# tablespace for testing, because partitioned tables cannot use pg_default
# explicitly and we want to test that table creation with tablespace works
# for partitioned tables.
my $ts = $node->basedir . '/regress_pgbench_tap_1_ts_dir';
mkdir $ts or die "cannot create directory $ts";
# this takes care of WIN-specific path issues
my $ets = TestLib::perl2host($ts);
# the next commands will issue a syntax error if the path contains a "'"
$node->safe_psql('postgres',
"CREATE TABLESPACE regress_pgbench_tap_1_ts LOCATION '$ets';"
);
# Test concurrent OID generation via pg_enum_oid_index. This indirectly # Test concurrent OID generation via pg_enum_oid_index. This indirectly
# exercises LWLock and spinlock concurrency. # exercises LWLock and spinlock concurrency.
my $labels = join ',', map { "'l$_'" } 1 .. 1000; my $labels = join ',', map { "'l$_'" } 1 .. 1000;
...@@ -100,12 +113,13 @@ pgbench( ...@@ -100,12 +113,13 @@ pgbench(
# Again, with all possible options # Again, with all possible options
pgbench( pgbench(
'--initialize --init-steps=dtpvg --scale=1 --unlogged-tables --fillfactor=98 --foreign-keys --quiet --tablespace=pg_default --index-tablespace=pg_default', '--initialize --init-steps=dtpvg --scale=1 --unlogged-tables --fillfactor=98 --foreign-keys --quiet --tablespace=regress_pgbench_tap_1_ts --index-tablespace=regress_pgbench_tap_1_ts --partitions=2 --partition-method=hash',
0, 0,
[qr{^$}i], [qr{^$}i],
[ [
qr{dropping old tables}, qr{dropping old tables},
qr{creating tables}, qr{creating tables},
qr{creating 2 partitions},
qr{vacuuming}, qr{vacuuming},
qr{creating primary keys}, qr{creating primary keys},
qr{creating foreign keys}, qr{creating foreign keys},
...@@ -116,12 +130,13 @@ pgbench( ...@@ -116,12 +130,13 @@ pgbench(
# Test interaction of --init-steps with legacy step-selection options # Test interaction of --init-steps with legacy step-selection options
pgbench( pgbench(
'--initialize --init-steps=dtpvgvv --no-vacuum --foreign-keys --unlogged-tables', '--initialize --init-steps=dtpvgvv --no-vacuum --foreign-keys --unlogged-tables --partitions=3',
0, 0,
[qr{^$}], [qr{^$}],
[ [
qr{dropping old tables}, qr{dropping old tables},
qr{creating tables}, qr{creating tables},
qr{creating 3 partitions},
qr{creating primary keys}, qr{creating primary keys},
qr{.* of .* tuples \(.*\) done}, qr{.* of .* tuples \(.*\) done},
qr{creating foreign keys}, qr{creating foreign keys},
...@@ -910,5 +925,6 @@ check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10, ...@@ -910,5 +925,6 @@ check_pgbench_logs($bdir, '001_pgbench_log_3', 1, 10, 10,
qr{^\d \d{1,2} \d+ \d \d+ \d+$}); qr{^\d \d{1,2} \d+ \d \d+ \d+$});
# done # done
$node->safe_psql('postgres', 'DROP TABLESPACE regress_pgbench_tap_1_ts');
$node->stop; $node->stop;
done_testing(); done_testing();
...@@ -157,6 +157,13 @@ my @options = ( ...@@ -157,6 +157,13 @@ my @options = (
qr{error while setting random seed from --random-seed option} qr{error while setting random seed from --random-seed option}
] ]
], ],
[ 'bad partition type', '-i --partition-method=BAD', [qr{"range"}, qr{"hash"}, qr{"BAD"}] ],
[ 'bad partition number', '-i --partitions -1', [ qr{invalid number of partitions: "-1"} ] ],
[
'partition method without partitioning',
'-i --partition-method=hash',
[ qr{partition-method requires greater than zero --partitions} ]
],
# logging sub-options # logging sub-options
[ [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment