Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1f1dac8

Browse files
author
Your Name
committed
Improve pgbench: add partitioning of tellers and branches tables
1 parent ec97e14 commit 1f1dac8

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,14 +1192,14 @@ DefineIndex(Oid relationId,
11921192
*/
11931193
if (childrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
11941194
{
1195-
if (stmt->unique || stmt->primary)
1195+
/* if (stmt->unique || stmt->primary)
11961196
ereport(ERROR,
11971197
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
11981198
errmsg("cannot create unique index on partitioned table \"%s\"",
11991199
RelationGetRelationName(rel)),
12001200
errdetail("Table \"%s\" contains partitions that are foreign tables.",
12011201
RelationGetRelationName(rel))));
1202-
1202+
*/
12031203
table_close(childrel, lockmode);
12041204
continue;
12051205
}

src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,15 +1451,15 @@ ProcessUtilitySlow(ParseState *pstate,
14511451
relkind != RELKIND_FOREIGN_TABLE)
14521452
elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
14531453
relkind, stmt->relation->relname);
1454-
1454+
/*
14551455
if (relkind == RELKIND_FOREIGN_TABLE &&
14561456
(stmt->unique || stmt->primary))
14571457
ereport(ERROR,
14581458
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
14591459
errmsg("cannot create unique index on partitioned table \"%s\"",
14601460
stmt->relation->relname),
14611461
errdetail("Table \"%s\" contains partitions that are foreign tables.",
1462-
stmt->relation->relname)));
1462+
stmt->relation->relname)));*/
14631463
}
14641464
list_free(inheritors);
14651465
}

src/bin/pgbench/pgbench.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,7 +3629,7 @@ initDropTables(PGconn *con)
36293629
* with a known size, so we choose to partition it.
36303630
*/
36313631
static void
3632-
createPartitions(PGconn *con)
3632+
createPartitions(PGconn *con, const char *tablename)
36333633
{
36343634
char ff[64];
36353635

@@ -3644,7 +3644,8 @@ createPartitions(PGconn *con)
36443644
/* we must have to create some partitions */
36453645
Assert(partitions > 0);
36463646

3647-
fprintf(stderr, "creating %d partitions...\n", partitions);
3647+
fprintf(stderr, "creating %d partitions for relation %s...\n",
3648+
partitions, tablename);
36483649

36493650
for (int p = 1; p <= partitions; p++)
36503651
{
@@ -3673,18 +3674,20 @@ createPartitions(PGconn *con)
36733674
sprintf(maxvalue, "maxvalue");
36743675

36753676
snprintf(query, sizeof(query),
3676-
"create%s table pgbench_accounts_%d\n"
3677-
" partition of pgbench_accounts\n"
3677+
"create%s table %s_%d\n"
3678+
" partition of %s\n"
36783679
" for values from (%s) to (%s)%s\n",
3679-
unlogged_tables ? " unlogged" : "", p,
3680+
unlogged_tables ? " unlogged" : "",
3681+
tablename, p, tablename,
36803682
minvalue, maxvalue, ff);
36813683
}
36823684
else if (partition_method == PART_HASH)
36833685
snprintf(query, sizeof(query),
3684-
"create%s table pgbench_accounts_%d\n"
3685-
" partition of pgbench_accounts\n"
3686+
"create%s table %s_%d\n"
3687+
" partition of %s\n"
36863688
" for values with (modulus %d, remainder %d)%s\n",
3687-
unlogged_tables ? " unlogged" : "", p,
3689+
unlogged_tables ? " unlogged" : "",
3690+
tablename, p, tablename,
36883691
partitions, p - 1, ff);
36893692
else /* cannot get there */
36903693
Assert(0);
@@ -3753,14 +3756,25 @@ initCreateTables(PGconn *con)
37533756
char buffer[256];
37543757
const struct ddlinfo *ddl = &DDLs[i];
37553758
const char *cols;
3759+
const char *partcolname;
37563760

37573761
/* Construct new create table statement. */
37583762
opts[0] = '\0';
37593763

37603764
/* Partition pgbench_accounts table */
3761-
if (partition_method != PART_NONE && strcmp(ddl->table, "pgbench_accounts") == 0)
3765+
if (partition_method != PART_NONE && strcmp(ddl->table, "pgbench_history") != 0)
3766+
{
3767+
if (strcmp(ddl->table, "pgbench_accounts") == 0)
3768+
partcolname = "aid";
3769+
else if (strcmp(ddl->table, "pgbench_branches") == 0)
3770+
partcolname = "bid";
3771+
else if (strcmp(ddl->table, "pgbench_tellers") == 0)
3772+
partcolname = "tid";
3773+
37623774
snprintf(opts + strlen(opts), sizeof(opts) - strlen(opts),
3763-
" partition by %s (aid)", PARTITION_METHOD[partition_method]);
3775+
" partition by %s (%s)",
3776+
PARTITION_METHOD[partition_method], partcolname);
3777+
}
37643778
else if (ddl->declare_fillfactor)
37653779
/* fillfactor is only expected on actual tables */
37663780
append_fillfactor(opts, sizeof(opts));
@@ -3783,10 +3797,11 @@ initCreateTables(PGconn *con)
37833797
ddl->table, cols, opts);
37843798

37853799
executeStatement(con, buffer);
3786-
}
37873800

3788-
if (partition_method != PART_NONE)
3789-
createPartitions(con);
3801+
if (partition_method != PART_NONE &&
3802+
strcmp(ddl->table, "pgbench_history") != 0)
3803+
createPartitions(con, ddl->table);
3804+
}
37903805
}
37913806

37923807
/*

0 commit comments

Comments
 (0)