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

Commit 67c9e44

Browse files
committed
Furter pg_upgrade optimizations to reduce function call argument count.
1 parent 6e6bee9 commit 67c9e44

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

contrib/pg_upgrade/check.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ void
209209
check_cluster_versions(void)
210210
{
211211
/* get old and new cluster versions */
212-
old_cluster.major_version = get_major_server_version(&old_cluster, &old_cluster.major_version_str);
213-
new_cluster.major_version = get_major_server_version(&new_cluster, &new_cluster.major_version_str);
212+
old_cluster.major_version = get_major_server_version(&old_cluster);
213+
new_cluster.major_version = get_major_server_version(&new_cluster);
214214

215215
/* We allow upgrades from/to the same major version for alpha/beta upgrades */
216216

contrib/pg_upgrade/info.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
static void get_db_infos(ClusterInfo *cluster);
1616
static void dbarr_print(ClusterInfo *cluster);
1717
static void relarr_print(RelInfoArr *arr);
18-
static void get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo,
19-
RelInfoArr *relarr);
18+
static void get_rel_infos(ClusterInfo *cluster, const int dbnum);
2019
static void relarr_free(RelInfoArr *rel_arr);
2120
static void map_rel(const RelInfo *oldrel,
2221
const RelInfo *newrel, const DbInfo *old_db,
@@ -272,8 +271,7 @@ get_db_and_rel_infos(ClusterInfo *cluster)
272271
get_db_infos(cluster);
273272

274273
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
275-
get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum],
276-
&cluster->dbarr.dbs[dbnum].rel_arr);
274+
get_rel_infos(cluster, dbnum);
277275

278276
if (log_opts.debug)
279277
dbarr_print(cluster);
@@ -290,9 +288,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
290288
* FirstNormalObjectId belongs to the user
291289
*/
292290
static void
293-
get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
291+
get_rel_infos(ClusterInfo *cluster, const int dbnum)
294292
{
295-
PGconn *conn = connectToServer(cluster, dbinfo->db_name);
293+
PGconn *conn = connectToServer(cluster,
294+
cluster->dbarr.dbs[dbnum].db_name);
296295
PGresult *res;
297296
RelInfo *relinfos;
298297
int ntups;
@@ -374,16 +373,16 @@ get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
374373
tblspace = PQgetvalue(res, relnum, i_spclocation);
375374
/* if no table tablespace, use the database tablespace */
376375
if (strlen(tblspace) == 0)
377-
tblspace = dbinfo->db_tblspace;
376+
tblspace = cluster->dbarr.dbs[dbnum].db_tblspace;
378377
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
379378
}
380379
PQclear(res);
381380

382381
PQfinish(conn);
383382

384-
relarr->rels = relinfos;
385-
relarr->nrels = num_rels;
386-
relarr->last_relname_lookup = 0;
383+
cluster->dbarr.dbs[dbnum].rel_arr.rels = relinfos;
384+
cluster->dbarr.dbs[dbnum].rel_arr.nrels = num_rels;
385+
cluster->dbarr.dbs[dbnum].rel_arr.last_relname_lookup = 0;
387386
}
388387

389388

contrib/pg_upgrade/pg_upgrade.c

-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ cleanup(void)
384384
dbarr_free(&new_cluster.dbarr);
385385
pg_free(log_opts.filename);
386386
pg_free(os_info.user);
387-
pg_free(old_cluster.major_version_str);
388-
pg_free(new_cluster.major_version_str);
389387
pg_free(old_cluster.controldata.lc_collate);
390388
pg_free(new_cluster.controldata.lc_collate);
391389
pg_free(old_cluster.controldata.lc_ctype);

contrib/pg_upgrade/pg_upgrade.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef struct
179179
char *bindir; /* pathname for cluster's executable directory */
180180
unsigned short port; /* port number where postmaster is waiting */
181181
uint32 major_version; /* PG_VERSION of cluster */
182-
char *major_version_str; /* string PG_VERSION of cluster */
182+
char major_version_str[64]; /* string PG_VERSION of cluster */
183183
Oid pg_database_oid; /* OID of pg_database relation */
184184
char *libpath; /* pathname for cluster's pkglibdir */
185185
char *tablespace_suffix; /* directory specification */
@@ -357,7 +357,7 @@ PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
357357

358358
void start_postmaster(ClusterInfo *cluster, bool quiet);
359359
void stop_postmaster(bool fast, bool quiet);
360-
uint32 get_major_server_version(ClusterInfo *cluster, char **verstr);
360+
uint32 get_major_server_version(ClusterInfo *cluster);
361361
void check_for_libpq_envvars(void);
362362

363363

contrib/pg_upgrade/server.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,21 @@ get_postmaster_pid(const char *datadir)
129129
* is retrieved by reading the PG_VERSION file.
130130
*/
131131
uint32
132-
get_major_server_version(ClusterInfo *cluster, char **verstr)
132+
get_major_server_version(ClusterInfo *cluster)
133133
{
134134
const char *datadir = cluster->pgdata;
135135
FILE *version_fd;
136-
char ver_file[MAXPGPATH];
136+
char ver_filename[MAXPGPATH];
137137
int integer_version = 0;
138138
int fractional_version = 0;
139139

140-
*verstr = pg_malloc(64);
141-
142-
snprintf(ver_file, sizeof(ver_file), "%s/PG_VERSION", datadir);
143-
if ((version_fd = fopen(ver_file, "r")) == NULL)
140+
snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION", datadir);
141+
if ((version_fd = fopen(ver_filename, "r")) == NULL)
144142
return 0;
145143

146-
if (fscanf(version_fd, "%63s", *verstr) == 0 ||
147-
sscanf(*verstr, "%d.%d", &integer_version, &fractional_version) != 2)
144+
if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
145+
sscanf(cluster->major_version_str, "%d.%d", &integer_version,
146+
&fractional_version) != 2)
148147
{
149148
pg_log(PG_FATAL, "could not get version from %s\n", datadir);
150149
fclose(version_fd);

0 commit comments

Comments
 (0)