1467
const char *table; /* table name */
1468
const char *smcols; /* column decls if accountIDs are 32 bits */
1469
const char *bigcols; /* column decls if accountIDs are 64 bits */
1468
1470
int declare_fillfactor;
1470
struct ddlinfo DDLs[] = {
1472
static const struct ddlinfo DDLs[] = {
1472
1474
"pgbench_history",
1473
scale >= SCALE_32BIT_THRESHOLD
1474
? "tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)"
1475
: "tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
1475
"tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)",
1476
"tid int,bid int,aid bigint,delta int,mtime timestamp,filler char(22)",
1479
1480
"pgbench_tellers",
1480
1481
"tid int not null,bid int,tbalance int,filler char(84)",
1482
"tid int not null,bid int,tbalance int,filler char(84)",
1484
1486
"pgbench_accounts",
1485
scale >= SCALE_32BIT_THRESHOLD
1486
? "aid bigint not null,bid int,abalance int,filler char(84)"
1487
: "aid int not null,bid int,abalance int,filler char(84)",
1487
"aid int not null,bid int,abalance int,filler char(84)",
1488
"aid bigint not null,bid int,abalance int,filler char(84)",
1491
1492
"pgbench_branches",
1492
1493
"bid int not null,bbalance int,filler char(88)",
1494
"bid int not null,bbalance int,filler char(88)",
1496
static char *DDLAFTERs[] = {
1498
static const char *const DDLINDEXes[] = {
1497
1499
"alter table pgbench_branches add primary key (bid)",
1498
1500
"alter table pgbench_tellers add primary key (tid)",
1499
1501
"alter table pgbench_accounts add primary key (aid)"
1501
static char *DDLKEYs[] = {
1503
static const char *const DDLKEYs[] = {
1502
1504
"alter table pgbench_tellers add foreign key (bid) references pgbench_branches",
1503
1505
"alter table pgbench_accounts add foreign key (bid) references pgbench_branches",
1504
1506
"alter table pgbench_history add foreign key (bid) references pgbench_branches",
1527
1529
char opts[256];
1528
1530
char buffer[256];
1529
struct ddlinfo *ddl = &DDLs[i];
1531
const struct ddlinfo *ddl = &DDLs[i];
1531
1534
/* Remove old table, if it exists. */
1532
snprintf(buffer, 256, "drop table if exists %s", ddl->table);
1535
snprintf(buffer, sizeof(buffer), "drop table if exists %s", ddl->table);
1533
1536
executeStatement(con, buffer);
1535
1538
/* Construct new create table statement. */
1536
1539
opts[0] = '\0';
1537
1540
if (ddl->declare_fillfactor)
1538
snprintf(opts + strlen(opts), 256 - strlen(opts),
1541
snprintf(opts + strlen(opts), sizeof(opts) - strlen(opts),
1539
1542
" with (fillfactor=%d)", fillfactor);
1540
1543
if (tablespace != NULL)
1544
1547
escape_tablespace = PQescapeIdentifier(con, tablespace,
1545
1548
strlen(tablespace));
1546
snprintf(opts + strlen(opts), 256 - strlen(opts),
1549
snprintf(opts + strlen(opts), sizeof(opts) - strlen(opts),
1547
1550
" tablespace %s", escape_tablespace);
1548
1551
PQfreemem(escape_tablespace);
1550
snprintf(buffer, 256, "create%s table %s(%s)%s",
1554
cols = (scale >= SCALE_32BIT_THRESHOLD) ? ddl->bigcols : ddl->smcols;
1556
snprintf(buffer, sizeof(buffer), "create%s table %s(%s)%s",
1551
1557
unlogged_tables ? " unlogged" : "",
1552
ddl->table, ddl->cols, opts);
1558
ddl->table, cols, opts);
1554
1560
executeStatement(con, buffer);
1559
1565
for (i = 0; i < nbranches * scale; i++)
1561
snprintf(sql, 256, "insert into pgbench_branches(bid,bbalance) values(%d,0)", i + 1);
1567
snprintf(sql, sizeof(sql),
1568
"insert into pgbench_branches(bid,bbalance) values(%d,0)",
1562
1570
executeStatement(con, sql);
1565
1573
for (i = 0; i < ntellers * scale; i++)
1567
snprintf(sql, 256, "insert into pgbench_tellers(tid,bid,tbalance) values (%d,%d,0)",
1575
snprintf(sql, sizeof(sql),
1576
"insert into pgbench_tellers(tid,bid,tbalance) values (%d,%d,0)",
1568
1577
i + 1, i / ntellers + 1);
1569
1578
executeStatement(con, sql);
1594
1603
int64 j = k + 1;
1596
snprintf(sql, 256, INT64_FORMAT "\t" INT64_FORMAT "\t%d\t\n", j, k / naccounts + 1, 0);
1605
snprintf(sql, sizeof(sql),
1606
INT64_FORMAT "\t" INT64_FORMAT "\t%d\t\n",
1607
j, k / naccounts + 1, 0);
1597
1608
if (PQputline(con, sql))
1599
1610
fprintf(stderr, "PQputline failed\n");
1665
1676
* create indexes
1667
1678
fprintf(stderr, "set primary keys...\n");
1668
for (i = 0; i < lengthof(DDLAFTERs); i++)
1679
for (i = 0; i < lengthof(DDLINDEXes); i++)
1670
1681
char buffer[256];
1672
strncpy(buffer, DDLAFTERs[i], 256);
1683
strlcpy(buffer, DDLINDEXes[i], sizeof(buffer));
1674
1685
if (index_tablespace != NULL)
1678
1689
escape_tablespace = PQescapeIdentifier(con, index_tablespace,
1679
1690
strlen(index_tablespace));
1680
snprintf(buffer + strlen(buffer), 256 - strlen(buffer),
1691
snprintf(buffer + strlen(buffer), sizeof(buffer) - strlen(buffer),
1681
1692
" using index tablespace %s", escape_tablespace);
1682
1693
PQfreemem(escape_tablespace);