* Create primary keys on the standard tables */
| 4365 | * Create primary keys on the standard tables |
| 4366 | */ |
| 4367 | static void |
| 4368 | initCreatePKeys(PGconn *con) |
| 4369 | { |
| 4370 | static const char *const DDLINDEXes[] = { |
| 4371 | "alter table pgbench_branches add primary key (bid)", |
| 4372 | "alter table pgbench_tellers add primary key (tid)", |
| 4373 | "alter table pgbench_accounts add primary key (aid)" |
| 4374 | }; |
| 4375 | static const char *const NON_UNIQUE_INDEX_DDLINDEXes[] = { |
| 4376 | "CREATE INDEX branch_idx ON pgbench_branches (bid) ", |
| 4377 | "CREATE INDEX teller_idx ON pgbench_tellers (tid) ", |
| 4378 | "CREATE INDEX account_idx ON pgbench_accounts (aid) " |
| 4379 | }; |
| 4380 | StaticAssertStmt(lengthof(DDLINDEXes) == lengthof(NON_UNIQUE_INDEX_DDLINDEXes), |
| 4381 | "NON_UNIQUE_INDEX_DDLINDEXes must have same size as DDLINDEXes"); |
| 4382 | int i; |
| 4383 | PQExpBufferData query; |
| 4384 | |
| 4385 | if (use_unique_key) |
| 4386 | fprintf(stderr, "creating primary keys...\n"); |
| 4387 | else |
| 4388 | fprintf(stderr, "creating non-unique keys...\n"); |
| 4389 | |
| 4390 | initPQExpBuffer(&query); |
| 4391 | |
| 4392 | for (i = 0; i < lengthof(DDLINDEXes); i++) |
| 4393 | { |
| 4394 | |
| 4395 | resetPQExpBuffer(&query); |
| 4396 | if (use_unique_key) |
| 4397 | appendPQExpBufferStr(&query, DDLINDEXes[i]); |
| 4398 | else |
| 4399 | appendPQExpBufferStr(&query, NON_UNIQUE_INDEX_DDLINDEXes[i]); |
| 4400 | |
| 4401 | |
| 4402 | if (index_tablespace != NULL) |
| 4403 | { |
| 4404 | char *escape_tablespace; |
| 4405 | |
| 4406 | escape_tablespace = PQescapeIdentifier(con, index_tablespace, |
| 4407 | strlen(index_tablespace)); |
| 4408 | appendPQExpBuffer(&query, " using index tablespace %s", escape_tablespace); |
| 4409 | PQfreemem(escape_tablespace); |
| 4410 | } |
| 4411 | |
| 4412 | executeStatement(con, query.data); |
| 4413 | } |
| 4414 | |
| 4415 | termPQExpBuffer(&query); |
| 4416 | } |
| 4417 | |
| 4418 | /* |
| 4419 | * Create foreign key constraints between the standard tables |
no test coverage detected