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

Function initGenerateDataClientSide

src/bin/pgbench/pgbench.c:4170–4300  ·  view source on GitHub ↗

* Fill the standard tables with some data generated and sent from the client */

Source from the content-addressed store, hash-verified

4168 * Fill the standard tables with some data generated and sent from the client
4169 */
4170static void
4171initGenerateDataClientSide(PGconn *con)
4172{
4173 PQExpBufferData sql;
4174 PGresult *res;
4175 int i;
4176 int64 k;
4177
4178 /* used to track elapsed time and estimate of the remaining time */
4179 pg_time_usec_t start;
4180 int log_interval = 1;
4181
4182 /* Stay on the same line if reporting to a terminal */
4183 char eol = isatty(fileno(stderr)) ? '\r' : '\n';
4184
4185 fprintf(stderr, "generating data (client-side)...\n");
4186
4187 /*
4188 * we do all of this in one transaction to enable the backend's
4189 * data-loading optimizations
4190 */
4191 executeStatement(con, "begin");
4192
4193 /* truncate away any old data */
4194 initTruncateTables(con);
4195
4196 initPQExpBuffer(&sql);
4197
4198 /*
4199 * fill branches, tellers, accounts in that order in case foreign keys
4200 * already exist
4201 */
4202 for (i = 0; i < nbranches * scale; i++)
4203 {
4204 /* "filler" column defaults to NULL */
4205 printfPQExpBuffer(&sql,
4206 "insert into pgbench_branches(bid,bbalance) values(%d,0)",
4207 i + 1);
4208 executeStatement(con, sql.data);
4209 }
4210
4211 for (i = 0; i < ntellers * scale; i++)
4212 {
4213 /* "filler" column defaults to NULL */
4214 printfPQExpBuffer(&sql,
4215 "insert into pgbench_tellers(tid,bid,tbalance) values (%d,%d,0)",
4216 i + 1, i / ntellers + 1);
4217 executeStatement(con, sql.data);
4218 }
4219
4220 /*
4221 * accounts is big enough to be worth using COPY and tracking runtime
4222 */
4223 res = PQexec(con, "copy pgbench_accounts from stdin");
4224 if (PQresultStatus(res) != PGRES_COPY_IN)
4225 {
4226 pg_log_fatal("unexpected copy in result: %s", PQerrorMessage(con));
4227 exit(1);

Callers 1

runInitStepsFunction · 0.85

Calls 12

executeStatementFunction · 0.85
initTruncateTablesFunction · 0.85
initPQExpBufferFunction · 0.85
printfPQExpBufferFunction · 0.85
PQexecFunction · 0.85
PQresultStatusFunction · 0.85
PQerrorMessageFunction · 0.85
PQclearFunction · 0.85
pg_time_nowFunction · 0.85
PQputlineFunction · 0.85
PQendcopyFunction · 0.85
termPQExpBufferFunction · 0.85

Tested by

no test coverage detected