]> granicus.if.org Git - postgresql/commitdiff
Fix a pg_dump output ordering problem introduced in 8.3 by the addition of
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Jan 2009 20:44:53 +0000 (20:44 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 18 Jan 2009 20:44:53 +0000 (20:44 +0000)
array types for composite types.  Although pg_dump understood it wasn't
supposed to dump these array types as separate objects, it must include
them in the dependency ordering analysis, and it was improperly assigning them
the same relatively-high sort priority as regular types.  This resulted in
effectively moving composite types and tables up to that same high priority,
which broke any ordering requirements that weren't explicitly enforced by
dependencies.  In particular user-defined operator classes, which should come
out before tables, failed to do so.  Per report from Brendan Jurd.

In passing, also fix an ill-considered decision to give text search objects
the same sort priority as functions and operators --- the sort result looks
a lot nicer if different object types are kept separate.  The recent
foreign-data patch had copied that decision, making the sort ordering even
messier :-(

src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump_sort.c

index c284bbb2da9637cd61ff252a237769b13760ad28..a0eb8b41cd6901bc3abb2ddb76d3a08355a3e2aa 100644 (file)
@@ -12,7 +12,7 @@
  *     by PostgreSQL
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482 2008/01/30 18:35:55 tgl Exp $
+ *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.482.2.1 2009/01/18 20:44:53 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -953,28 +953,39 @@ selectDumpableTable(TableInfo *tbinfo)
 /*
  * selectDumpableType: policy-setting subroutine
  *             Mark a type as to be dumped or not
+ *
+ * If it's a table's rowtype or an autogenerated array type, we also apply a
+ * special type code to facilitate sorting into the desired order.  (We don't
+ * want to consider those to be ordinary types because that would bring tables
+ * up into the datatype part of the dump order.)  Those tests should be made
+ * first to ensure the objType change is applied regardless of namespace etc.
  */
 static void
 selectDumpableType(TypeInfo *tinfo)
 {
-       /* Dump only types in dumpable namespaces */
-       if (!tinfo->dobj.namespace->dobj.dump)
+       /* skip complex types, except for standalone composite types */
+       if (OidIsValid(tinfo->typrelid) &&
+               tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
+       {
                tinfo->dobj.dump = false;
+               tinfo->dobj.objType = DO_DUMMY_TYPE;
+       }
 
-       /* skip complex types, except for standalone composite types */
-       /* (note: this test should now be unnecessary) */
-       else if (OidIsValid(tinfo->typrelid) &&
-                        tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
+       /* skip auto-generated array types */
+       else if (tinfo->isArray)
+       {
+               tinfo->dobj.dump = false;
+               tinfo->dobj.objType = DO_DUMMY_TYPE;
+       }
+
+       /* dump only types in dumpable namespaces */
+       else if (!tinfo->dobj.namespace->dobj.dump)
                tinfo->dobj.dump = false;
 
        /* skip undefined placeholder types */
        else if (!tinfo->isDefined)
                tinfo->dobj.dump = false;
 
-       /* skip auto-generated array types */
-       else if (tinfo->isArray)
-               tinfo->dobj.dump = false;
-
        else
                tinfo->dobj.dump = true;
 }
@@ -2095,16 +2106,6 @@ getTypes(int *numTypes)
                tinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
                tinfo[i].shellType = NULL;
 
-               /*
-                * If it's a table's rowtype, use special type code to facilitate
-                * sorting into the desired order.      (We don't want to consider it an
-                * ordinary type because that would bring the table up into the
-                * datatype part of the dump order.)
-                */
-               if (OidIsValid(tinfo[i].typrelid) &&
-                       tinfo[i].typrelkind != RELKIND_COMPOSITE_TYPE)
-                       tinfo[i].dobj.objType = DO_TABLE_TYPE;
-
                if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
                        tinfo[i].isDefined = true;
                else
@@ -5393,8 +5394,8 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
                case DO_TABLE_DATA:
                        dumpTableData(fout, (TableDataInfo *) dobj);
                        break;
-               case DO_TABLE_TYPE:
-                       /* table rowtypes are never dumped separately */
+               case DO_DUMMY_TYPE:
+                       /* table rowtypes and array types are never dumped separately */
                        break;
                case DO_TSPARSER:
                        dumpTSParser(fout, (TSParserInfo *) dobj);
index d4b40e9d887b9518db72c54d86e9407a41aa587e..be0b3550ad7b569372a8e3b0a46527bd62e0c143 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.139 2008/01/01 19:45:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.139.2.1 2009/01/18 20:44:53 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -126,7 +126,7 @@ typedef enum
        DO_PROCLANG,
        DO_CAST,
        DO_TABLE_DATA,
-       DO_TABLE_TYPE,
+       DO_DUMMY_TYPE,
        DO_TSPARSER,
        DO_TSDICT,
        DO_TSTEMPLATE,
index e5807475e4ef72a277e235db34603b41f05684f2..128c3d2f99ee4d2a0f3d01be9a77fd1ec3d460cd 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.20 2008/01/01 19:45:55 momjian Exp $
+ *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.20.2.1 2009/01/18 20:44:53 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,7 +22,9 @@ static const char *modulename = gettext_noop("sorter");
  * Sort priority for object types when dumping a pre-7.3 database.
  * Objects are sorted by priority levels, and within an equal priority level
  * by OID.     (This is a relatively crude hack to provide semi-reasonable
- * behavior for old databases without full dependency info.)
+ * behavior for old databases without full dependency info.)  Note: text
+ * search objects can't really happen here, so the rather bogus priorities
+ * for them don't matter.
  */
 static const int oldObjectTypePriority[] =
 {
@@ -45,7 +47,7 @@ static const int oldObjectTypePriority[] =
        2,                                                      /* DO_PROCLANG */
        2,                                                      /* DO_CAST */
        9,                                                      /* DO_TABLE_DATA */
-       7,                                                      /* DO_TABLE_TYPE */
+       7,                                                      /* DO_DUMMY_TYPE */
        3,                                                      /* DO_TSPARSER */
        4,                                                      /* DO_TSDICT */
        3,                                                      /* DO_TSTEMPLATE */
@@ -69,23 +71,23 @@ static const int newObjectTypePriority[] =
        7,                                                      /* DO_OPCLASS */
        7,                                                      /* DO_OPFAMILY */
        9,                                                      /* DO_CONVERSION */
-       10,                                                     /* DO_TABLE */
-       12,                                                     /* DO_ATTRDEF */
-       17,                                                     /* DO_INDEX */
-       18,                                                     /* DO_RULE */
-       19,                                                     /* DO_TRIGGER */
-       16,                                                     /* DO_CONSTRAINT */
-       20,                                                     /* DO_FK_CONSTRAINT */
+       14,                                                     /* DO_TABLE */
+       16,                                                     /* DO_ATTRDEF */
+       21,                                                     /* DO_INDEX */
+       22,                                                     /* DO_RULE */
+       23,                                                     /* DO_TRIGGER */
+       20,                                                     /* DO_CONSTRAINT */
+       24,                                                     /* DO_FK_CONSTRAINT */
        2,                                                      /* DO_PROCLANG */
        8,                                                      /* DO_CAST */
-       13,                                                     /* DO_TABLE_DATA */
-       11,                                                     /* DO_TABLE_TYPE */
-       5,                                                      /* DO_TSPARSER */
-       6,                                                      /* DO_TSDICT */
-       5,                                                      /* DO_TSTEMPLATE */
-       7,                                                      /* DO_TSCONFIG */
-       14,                                                     /* DO_BLOBS */
-       15                                                      /* DO_BLOB_COMMENTS */
+       17,                                                     /* DO_TABLE_DATA */
+       15,                                                     /* DO_DUMMY_TYPE */
+       10,                                                     /* DO_TSPARSER */
+       12,                                                     /* DO_TSDICT */
+       11,                                                     /* DO_TSTEMPLATE */
+       13,                                                     /* DO_TSCONFIG */
+       18,                                                     /* DO_BLOBS */
+       19                                                      /* DO_BLOB_COMMENTS */
 };
 
 
@@ -1070,9 +1072,9 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
                                         "TABLE DATA %s  (ID %d OID %u)",
                                         obj->name, obj->dumpId, obj->catId.oid);
                        return;
-               case DO_TABLE_TYPE:
+               case DO_DUMMY_TYPE:
                        snprintf(buf, bufsize,
-                                        "TABLE TYPE %s  (ID %d OID %u)",
+                                        "DUMMY TYPE %s  (ID %d OID %u)",
                                         obj->name, obj->dumpId, obj->catId.oid);
                        return;
                case DO_TSPARSER: