MCPcopy Create free account
hub / github.com/apache/cloudberry / createPartitions

Function createPartitions

src/bin/pgbench/pgbench.c:3987–4051  ·  view source on GitHub ↗

* Create "pgbench_accounts" partitions if needed. * * This is the larger table of pgbench default tpc-b like schema * with a known size, so we choose to partition it. */

Source from the content-addressed store, hash-verified

3985 * with a known size, so we choose to partition it.
3986 */
3987static void
3988createPartitions(PGconn *con)
3989{
3990 PQExpBufferData query;
3991
3992 /* we must have to create some partitions */
3993 Assert(partitions > 0);
3994
3995 fprintf(stderr, "creating %d partitions...\n", partitions);
3996
3997 initPQExpBuffer(&query);
3998
3999 for (int p = 1; p <= partitions; p++)
4000 {
4001 if (partition_method == PART_RANGE)
4002 {
4003 int64 part_size = (naccounts * (int64) scale + partitions - 1) / partitions;
4004
4005 printfPQExpBuffer(&query,
4006 "create%s table pgbench_accounts_%d\n"
4007 " partition of pgbench_accounts\n"
4008 " for values from (",
4009 unlogged_tables ? " unlogged" : "", p);
4010
4011 /*
4012 * For RANGE, we use open-ended partitions at the beginning and
4013 * end to allow any valid value for the primary key. Although the
4014 * actual minimum and maximum values can be derived from the
4015 * scale, it is more generic and the performance is better.
4016 */
4017 if (p == 1)
4018 appendPQExpBufferStr(&query, "minvalue");
4019 else
4020 appendPQExpBuffer(&query, INT64_FORMAT, (p - 1) * part_size + 1);
4021
4022 appendPQExpBufferStr(&query, ") to (");
4023
4024 if (p < partitions)
4025 appendPQExpBuffer(&query, INT64_FORMAT, p * part_size + 1);
4026 else
4027 appendPQExpBufferStr(&query, "maxvalue");
4028
4029 appendPQExpBufferChar(&query, ')');
4030 }
4031 else if (partition_method == PART_HASH)
4032 printfPQExpBuffer(&query,
4033 "create%s table pgbench_accounts_%d\n"
4034 " partition of pgbench_accounts\n"
4035 " for values with (modulus %d, remainder %d)",
4036 unlogged_tables ? " unlogged" : "", p,
4037 partitions, p - 1);
4038 else /* cannot get there */
4039 Assert(0);
4040
4041 /*
4042 * Per ddlinfo in initCreateTables, fillfactor is needed on table
4043 * pgbench_accounts.
4044 */

Callers 1

initCreateTablesFunction · 0.85

Calls 7

initPQExpBufferFunction · 0.85
printfPQExpBufferFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendPQExpBufferFunction · 0.85
appendPQExpBufferCharFunction · 0.85
executeStatementFunction · 0.85
termPQExpBufferFunction · 0.85

Tested by

no test coverage detected