]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix core dump in pg_dump --binary-upgrade on zero-column composite type.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Oct 2014 16:49:15 +0000 (12:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Oct 2014 16:49:15 +0000 (12:49 -0400)
This reverts nearly all of commit 28f6cab61ab8958b1a7dfb019724687d92722538
in favor of just using the typrelid we already have in pg_dump's TypeInfo
struct for the composite type.  As coded, it'd crash if the composite type
had no attributes, since then the query would return no rows.

Back-patch to all supported versions.  It seems to not really be a problem
in 9.0 because that version rejects the syntax "create type t as ()", but
we might as well keep the logic similar in all affected branches.

Report and fix by Rushabh Lathia.

src/bin/pg_dump/pg_dump.c

index 53a513eff979f6fd53067114dbdd4eca7a231166..d086279ca7344aa4da0ccec7803e97bfcb299bb3 100644 (file)
@@ -7309,7 +7309,6 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
        int                     ntups;
        int                     i_attname;
        int                     i_atttypdefn;
-       int                     i_typrelid;
        int                     i;
 
        /* Set proper schema search path so type references list correctly */
@@ -7319,8 +7318,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
        /* We assume here that remoteVersion must be at least 70300 */
 
        appendPQExpBuffer(query, "SELECT a.attname, "
-                       "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
-                                         "typrelid "
+                       "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn "
                                          "FROM pg_catalog.pg_type t, pg_catalog.pg_attribute a "
                                          "WHERE t.oid = '%u'::pg_catalog.oid "
                                          "AND a.attrelid = t.typrelid "
@@ -7341,14 +7339,11 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
 
        i_attname = PQfnumber(res, "attname");
        i_atttypdefn = PQfnumber(res, "atttypdefn");
-       i_typrelid = PQfnumber(res, "typrelid");
 
        if (binary_upgrade)
        {
-               Oid                     typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
-
                binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
-               binary_upgrade_set_relfilenodes(q, typrelid, false);
+               binary_upgrade_set_relfilenodes(q, tyinfo->typrelid, false);
        }
 
        appendPQExpBuffer(q, "CREATE TYPE %s AS (",