]> granicus.if.org Git - postgresql/commitdiff
Furter pg_upgrade optimizations to reduce function call argument count.
authorBruce Momjian <bruce@momjian.us>
Sat, 1 Jan 2011 17:28:48 +0000 (12:28 -0500)
committerBruce Momjian <bruce@momjian.us>
Sat, 1 Jan 2011 17:28:48 +0000 (12:28 -0500)
contrib/pg_upgrade/check.c
contrib/pg_upgrade/info.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/server.c

index 839a3c92674e2f4e7926dbfbf14893ea2ee30d3a..5708e2ff0eb6d373f88f0458045a802423af6682 100644 (file)
@@ -209,8 +209,8 @@ void
 check_cluster_versions(void)
 {
        /* get old and new cluster versions */
-       old_cluster.major_version = get_major_server_version(&old_cluster, &old_cluster.major_version_str);
-       new_cluster.major_version = get_major_server_version(&new_cluster, &new_cluster.major_version_str);
+       old_cluster.major_version = get_major_server_version(&old_cluster);
+       new_cluster.major_version = get_major_server_version(&new_cluster);
 
        /* We allow upgrades from/to the same major version for alpha/beta upgrades */
 
index e44798a81700f3f055b3c3ea58167cce9452db40..7651096113f99148dbe3c7fae87df9701bb5c053 100644 (file)
@@ -15,8 +15,7 @@
 static void get_db_infos(ClusterInfo *cluster);
 static void dbarr_print(ClusterInfo *cluster);
 static void relarr_print(RelInfoArr *arr);
-static void get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo,
-                         RelInfoArr *relarr);
+static void get_rel_infos(ClusterInfo *cluster, const int dbnum);
 static void relarr_free(RelInfoArr *rel_arr);
 static void map_rel(const RelInfo *oldrel,
                const RelInfo *newrel, const DbInfo *old_db,
@@ -272,8 +271,7 @@ get_db_and_rel_infos(ClusterInfo *cluster)
        get_db_infos(cluster);
 
        for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
-               get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum],
-                                         &cluster->dbarr.dbs[dbnum].rel_arr);
+               get_rel_infos(cluster, dbnum);
 
        if (log_opts.debug)
                dbarr_print(cluster);
@@ -290,9 +288,10 @@ get_db_and_rel_infos(ClusterInfo *cluster)
  * FirstNormalObjectId belongs to the user
  */
 static void
-get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
+get_rel_infos(ClusterInfo *cluster, const int dbnum)
 {
-       PGconn     *conn = connectToServer(cluster, dbinfo->db_name);
+       PGconn     *conn = connectToServer(cluster,
+                                                                          cluster->dbarr.dbs[dbnum].db_name);
        PGresult   *res;
        RelInfo    *relinfos;
        int                     ntups;
@@ -374,16 +373,16 @@ get_rel_infos(ClusterInfo *cluster, const DbInfo *dbinfo, RelInfoArr *relarr)
                tblspace = PQgetvalue(res, relnum, i_spclocation);
                /* if no table tablespace, use the database tablespace */
                if (strlen(tblspace) == 0)
-                       tblspace = dbinfo->db_tblspace;
+                       tblspace = cluster->dbarr.dbs[dbnum].db_tblspace;
                strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
        }
        PQclear(res);
 
        PQfinish(conn);
 
-       relarr->rels = relinfos;
-       relarr->nrels = num_rels;
-       relarr->last_relname_lookup = 0;
+       cluster->dbarr.dbs[dbnum].rel_arr.rels = relinfos;
+       cluster->dbarr.dbs[dbnum].rel_arr.nrels = num_rels;
+       cluster->dbarr.dbs[dbnum].rel_arr.last_relname_lookup = 0;
 }
 
 
index d2ca08bb0b268589262846ab2dc509764422cd44..5b8bf7271cbdd434c82aa9404657b702d3110fc6 100644 (file)
@@ -384,8 +384,6 @@ cleanup(void)
        dbarr_free(&new_cluster.dbarr);
        pg_free(log_opts.filename);
        pg_free(os_info.user);
-       pg_free(old_cluster.major_version_str);
-       pg_free(new_cluster.major_version_str);
        pg_free(old_cluster.controldata.lc_collate);
        pg_free(new_cluster.controldata.lc_collate);
        pg_free(old_cluster.controldata.lc_ctype);
index b6ce965731bfb08ad4393f9a63bef146924a8f7f..5405209fe9702819286449b2190ad0dd0a8ca5f3 100644 (file)
@@ -179,7 +179,7 @@ typedef struct
        char       *bindir;                     /* pathname for cluster's executable directory */
        unsigned short port;            /* port number where postmaster is waiting */
        uint32          major_version;  /* PG_VERSION of cluster */
-       char       *major_version_str;          /* string PG_VERSION of cluster */
+       char       major_version_str[64];               /* string PG_VERSION of cluster */
        Oid                     pg_database_oid;        /* OID of pg_database relation */
        char       *libpath;            /* pathname for cluster's pkglibdir */
        char       *tablespace_suffix;          /* directory specification */
@@ -357,7 +357,7 @@ PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
 
 void           start_postmaster(ClusterInfo *cluster, bool quiet);
 void           stop_postmaster(bool fast, bool quiet);
-uint32 get_major_server_version(ClusterInfo *cluster, char **verstr);
+uint32 get_major_server_version(ClusterInfo *cluster);
 void           check_for_libpq_envvars(void);
 
 
index 56dcb10a5e33caff0466fbe31b67ab244bfd1dcf..785e2eea087fd459808de8338f8ceee80f261c75 100644 (file)
@@ -129,22 +129,21 @@ get_postmaster_pid(const char *datadir)
  * is retrieved by reading the PG_VERSION file.
  */
 uint32
-get_major_server_version(ClusterInfo *cluster, char **verstr)
+get_major_server_version(ClusterInfo *cluster)
 {
        const char *datadir = cluster->pgdata;
        FILE       *version_fd;
-       char            ver_file[MAXPGPATH];
+       char            ver_filename[MAXPGPATH];
        int                     integer_version = 0;
        int                     fractional_version = 0;
 
-       *verstr = pg_malloc(64);
-
-       snprintf(ver_file, sizeof(ver_file), "%s/PG_VERSION", datadir);
-       if ((version_fd = fopen(ver_file, "r")) == NULL)
+       snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION", datadir);
+       if ((version_fd = fopen(ver_filename, "r")) == NULL)
                return 0;
 
-       if (fscanf(version_fd, "%63s", *verstr) == 0 ||
-               sscanf(*verstr, "%d.%d", &integer_version, &fractional_version) != 2)
+       if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
+               sscanf(cluster->major_version_str, "%d.%d", &integer_version,
+                          &fractional_version) != 2)
        {
                pg_log(PG_FATAL, "could not get version from %s\n", datadir);
                fclose(version_fd);