Skip to content

Commit 5830a19

Browse files
gbartolinihackorum
authored andcommitted
Include pgbench_history in partitioning method for pgbench
If partitioning, make sure that pgbench_history is also partitioned with the same criteria. Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
1 parent b597835 commit 5830a19

2 files changed

Lines changed: 38 additions & 27 deletions

File tree

doc/src/sgml/ref/pgbench.sgml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
364364
<term><option>--partition-method=<replaceable>NAME</replaceable></option></term>
365365
<listitem>
366366
<para>
367-
Create a partitioned <literal>pgbench_accounts</literal> table with
368-
<replaceable>NAME</replaceable> method.
367+
Create partitioned <literal>pgbench_accounts</literal> and <literal>pgbench_history</literal>
368+
tables with <replaceable>NAME</replaceable> method.
369369
Expected values are <literal>range</literal> or <literal>hash</literal>.
370370
This option requires that <option>--partitions</option> is set to non-zero.
371371
If unspecified, default is <literal>range</literal>.
@@ -377,9 +377,9 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
377377
<term><option>--partitions=<replaceable>NUM</replaceable></option></term>
378378
<listitem>
379379
<para>
380-
Create a partitioned <literal>pgbench_accounts</literal> table with
381-
<replaceable>NUM</replaceable> partitions of nearly equal size for
382-
the scaled number of accounts.
380+
Create partitioned <literal>pgbench_accounts</literal> and <literal>pgbench_history</literal>
381+
tables with <replaceable>NUM</replaceable> partitions of nearly equal size for
382+
the scaled number of accounts and future history records.
383383
Default is <literal>0</literal>, meaning no partitioning.
384384
</para>
385385
</listitem>

src/bin/pgbench/pgbench.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ static char *tablespace = NULL;
218218
static char *index_tablespace = NULL;
219219

220220
/*
221-
* Number of "pgbench_accounts" partitions. 0 is the default and means no
222-
* partitioning.
221+
* Number of "pgbench_accounts" and "pgbench_history" partitions.
222+
* 0 is the default and means no partitioning.
223223
*/
224224
static int partitions = 0;
225225

@@ -926,8 +926,10 @@ usage(void)
926926
" --index-tablespace=TABLESPACE\n"
927927
" create indexes in the specified tablespace\n"
928928
" --partition-method=(range|hash)\n"
929-
" partition pgbench_accounts with this method (default: range)\n"
930-
" --partitions=NUM partition pgbench_accounts into NUM parts (default: 0)\n"
929+
" partition pgbench_accounts and pgbench_history with this method"
930+
" (default: range)\n"
931+
" --partitions=NUM partition pgbench_accounts and pgbench_history into NUM parts"
932+
" (default: 0)\n"
931933
" --tablespace=TABLESPACE create tables in the specified tablespace\n"
932934
" --unlogged-tables create tables as unlogged tables\n"
933935
"\nOptions to select what to run:\n"
@@ -4817,20 +4819,22 @@ initDropTables(PGconn *con)
48174819
}
48184820

48194821
/*
4820-
* Create "pgbench_accounts" partitions if needed.
4822+
* Create "pgbench_accounts" and/or "pgbench_history" partitions if needed.
48214823
*
4822-
* This is the larger table of pgbench default tpc-b like schema
4823-
* with a known size, so we choose to partition it.
4824+
* "pgbench_accounts" is the larger table of pgbench default tpc-b like schema
4825+
* with a known size, so we choose to partition it. "pgbench_history" on the
4826+
* contrary is dynamically populated when pgbench runs, and we partition it
4827+
* based on the same criteria used in "pgbench_accounts".
48244828
*/
48254829
static void
4826-
createPartitions(PGconn *con)
4830+
createPartitions(PGconn *con, const char *table)
48274831
{
48284832
PQExpBufferData query;
48294833

48304834
/* we must have to create some partitions */
48314835
Assert(partitions > 0);
48324836

4833-
fprintf(stderr, "creating %d partitions...\n", partitions);
4837+
fprintf(stderr, "creating %d partitions for table %s ...\n", partitions, table);
48344838

48354839
initPQExpBuffer(&query);
48364840

@@ -4841,10 +4845,10 @@ createPartitions(PGconn *con)
48414845
int64 part_size = (naccounts * (int64) scale + partitions - 1) / partitions;
48424846

48434847
printfPQExpBuffer(&query,
4844-
"create%s table pgbench_accounts_%d\n"
4845-
" partition of pgbench_accounts\n"
4848+
"create%s table %s_%d\n"
4849+
" partition of %s\n"
48464850
" for values from (",
4847-
unlogged_tables ? " unlogged" : "", p);
4851+
unlogged_tables ? " unlogged" : "", table, p, table);
48484852

48494853
/*
48504854
* For RANGE, we use open-ended partitions at the beginning and
@@ -4868,19 +4872,20 @@ createPartitions(PGconn *con)
48684872
}
48694873
else if (partition_method == PART_HASH)
48704874
printfPQExpBuffer(&query,
4871-
"create%s table pgbench_accounts_%d\n"
4872-
" partition of pgbench_accounts\n"
4875+
"create%s table %s_%d\n"
4876+
" partition of %s\n"
48734877
" for values with (modulus %d, remainder %d)",
4874-
unlogged_tables ? " unlogged" : "", p,
4875-
partitions, p - 1);
4878+
unlogged_tables ? " unlogged" : "", table, p,
4879+
table, partitions, p - 1);
48764880
else /* cannot get there */
48774881
Assert(0);
48784882

48794883
/*
48804884
* Per ddlinfo in initCreateTables, fillfactor is needed on table
48814885
* pgbench_accounts.
48824886
*/
4883-
appendPQExpBuffer(&query, " with (fillfactor=%d)", fillfactor);
4887+
if (strcmp(table, "pgbench_accounts") == 0)
4888+
appendPQExpBuffer(&query, " with (fillfactor=%d)", fillfactor);
48844889

48854890
executeStatement(con, query.data);
48864891
}
@@ -4955,9 +4960,9 @@ initCreateTables(PGconn *con)
49554960
(scale >= SCALE_32BIT_THRESHOLD) ? ddl->bigcols : ddl->smcols);
49564961

49574962
/* Partition pgbench_accounts table */
4958-
if (partition_method != PART_NONE && strcmp(ddl->table, "pgbench_accounts") == 0)
4959-
appendPQExpBuffer(&query,
4960-
" partition by %s (aid)", PARTITION_METHOD[partition_method]);
4963+
if (partition_method != PART_NONE && (
4964+
strcmp(ddl->table, "pgbench_accounts") == 0 || strcmp(ddl->table, "pgbench_history") == 0))
4965+
appendPQExpBuffer(&query, " partition by %s (aid)", PARTITION_METHOD[partition_method]);
49614966
else if (ddl->declare_fillfactor)
49624967
{
49634968
/* fillfactor is only expected on actual tables */
@@ -4979,7 +4984,10 @@ initCreateTables(PGconn *con)
49794984
termPQExpBuffer(&query);
49804985

49814986
if (partition_method != PART_NONE)
4982-
createPartitions(con);
4987+
{
4988+
createPartitions(con, "pgbench_accounts");
4989+
createPartitions(con, "pgbench_history");
4990+
}
49834991
}
49844992

49854993
/*
@@ -7395,7 +7403,10 @@ main(int argc, char **argv)
73957403
fprintf(stderr, "starting vacuum...");
73967404
tryExecuteStatement(con, "vacuum pgbench_branches");
73977405
tryExecuteStatement(con, "vacuum pgbench_tellers");
7398-
tryExecuteStatement(con, "truncate pgbench_history");
7406+
if (partitions > 0)
7407+
tryExecuteStatement(con, "truncate pgbench_history CASCADE");
7408+
else
7409+
tryExecuteStatement(con, "truncate pgbench_history");
73997410
fprintf(stderr, "end.\n");
74007411

74017412
if (do_vacuum_accounts)

0 commit comments

Comments
 (0)