*/
int fillfactor = 100;
+/*
+ * create foreign key constraints on the tables?
+ */
+int foreign_keys = 0;
+
/*
* use unlogged tables?
*/
" -i invokes initialization mode\n"
" -F NUM fill factor\n"
" -s NUM scaling factor\n"
+ " --foreign-keys\n"
+ " create foreign key constraints between tables\n"
" --index-tablespace=TABLESPACE\n"
" create indexes in the specified tablespace\n"
" --tablespace=TABLESPACE\n"
};
struct ddlinfo DDLs[] = {
{
- "pgbench_branches",
- "bid int not null,bbalance int,filler char(88)",
- 1
+ "pgbench_history",
+ "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
+ 0
},
{
"pgbench_tellers",
1
},
{
- "pgbench_history",
- "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
- 0
+ "pgbench_branches",
+ "bid int not null,bbalance int,filler char(88)",
+ 1
}
};
static char *DDLAFTERs[] = {
"alter table pgbench_tellers add primary key (tid)",
"alter table pgbench_accounts add primary key (aid)"
};
+ static char *DDLKEYs[] = {
+ "alter table pgbench_tellers add foreign key (bid) references pgbench_branches",
+ "alter table pgbench_accounts add foreign key (bid) references pgbench_branches",
+ "alter table pgbench_history add foreign key (bid) references pgbench_branches",
+ "alter table pgbench_history add foreign key (tid) references pgbench_tellers",
+ "alter table pgbench_history add foreign key (aid) references pgbench_accounts"
+ };
PGconn *con;
PGresult *res;
/*
* create indexes
*/
- fprintf(stderr, "set primary key...\n");
+ fprintf(stderr, "set primary keys...\n");
for (i = 0; i < lengthof(DDLAFTERs); i++)
{
char buffer[256];
executeStatement(con, buffer);
}
+ /*
+ * create foreign keys
+ */
+ if (foreign_keys)
+ {
+ fprintf(stderr, "set foreign keys...\n");
+ for (i = 0; i < lengthof(DDLKEYs); i++)
+ {
+ executeStatement(con, DDLKEYs[i]);
+ }
+ }
+
/* vacuum */
fprintf(stderr, "vacuum...");
executeStatement(con, "vacuum analyze pgbench_branches");
int i;
static struct option long_options[] = {
+ {"foreign-keys", no_argument, &foreign_keys, 1},
{"index-tablespace", required_argument, NULL, 3},
{"tablespace", required_argument, NULL, 2},
{"unlogged-tables", no_argument, &unlogged_tables, 1},