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

Commit 390081e

Browse files
committed
Fix a pg_dump output ordering problem introduced in 8.3 by the addition of
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 :-(
1 parent fd1d4b3 commit 390081e

File tree

3 files changed

+50
-47
lines changed

3 files changed

+50
-47
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.513 2009/01/06 18:01:57 momjian Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.514 2009/01/18 20:44:45 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -1008,28 +1008,39 @@ selectDumpableTable(TableInfo *tbinfo)
10081008
/*
10091009
* selectDumpableType: policy-setting subroutine
10101010
* Mark a type as to be dumped or not
1011+
*
1012+
* If it's a table's rowtype or an autogenerated array type, we also apply a
1013+
* special type code to facilitate sorting into the desired order. (We don't
1014+
* want to consider those to be ordinary types because that would bring tables
1015+
* up into the datatype part of the dump order.) Those tests should be made
1016+
* first to ensure the objType change is applied regardless of namespace etc.
10111017
*/
10121018
static void
10131019
selectDumpableType(TypeInfo *tinfo)
10141020
{
1015-
/* Dump only types in dumpable namespaces */
1016-
if (!tinfo->dobj.namespace->dobj.dump)
1021+
/* skip complex types, except for standalone composite types */
1022+
if (OidIsValid(tinfo->typrelid) &&
1023+
tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
1024+
{
10171025
tinfo->dobj.dump = false;
1026+
tinfo->dobj.objType = DO_DUMMY_TYPE;
1027+
}
10181028

1019-
/* skip complex types, except for standalone composite types */
1020-
/* (note: this test should now be unnecessary) */
1021-
else if (OidIsValid(tinfo->typrelid) &&
1022-
tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
1029+
/* skip auto-generated array types */
1030+
else if (tinfo->isArray)
1031+
{
1032+
tinfo->dobj.dump = false;
1033+
tinfo->dobj.objType = DO_DUMMY_TYPE;
1034+
}
1035+
1036+
/* dump only types in dumpable namespaces */
1037+
else if (!tinfo->dobj.namespace->dobj.dump)
10231038
tinfo->dobj.dump = false;
10241039

10251040
/* skip undefined placeholder types */
10261041
else if (!tinfo->isDefined)
10271042
tinfo->dobj.dump = false;
10281043

1029-
/* skip auto-generated array types */
1030-
else if (tinfo->isArray)
1031-
tinfo->dobj.dump = false;
1032-
10331044
else
10341045
tinfo->dobj.dump = true;
10351046
}
@@ -2310,16 +2321,6 @@ getTypes(int *numTypes)
23102321
tinfo[i].typtype = *PQgetvalue(res, i, i_typtype);
23112322
tinfo[i].shellType = NULL;
23122323

2313-
/*
2314-
* If it's a table's rowtype, use special type code to facilitate
2315-
* sorting into the desired order. (We don't want to consider it an
2316-
* ordinary type because that would bring the table up into the
2317-
* datatype part of the dump order.)
2318-
*/
2319-
if (OidIsValid(tinfo[i].typrelid) &&
2320-
tinfo[i].typrelkind != RELKIND_COMPOSITE_TYPE)
2321-
tinfo[i].dobj.objType = DO_TABLE_TYPE;
2322-
23232324
if (strcmp(PQgetvalue(res, i, i_typisdefined), "t") == 0)
23242325
tinfo[i].isDefined = true;
23252326
else
@@ -5836,8 +5837,8 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
58365837
case DO_TABLE_DATA:
58375838
dumpTableData(fout, (TableDataInfo *) dobj);
58385839
break;
5839-
case DO_TABLE_TYPE:
5840-
/* table rowtypes are never dumped separately */
5840+
case DO_DUMMY_TYPE:
5841+
/* table rowtypes and array types are never dumped separately */
58415842
break;
58425843
case DO_TSPARSER:
58435844
dumpTSParser(fout, (TSParserInfo *) dobj);

src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.146 2009/01/07 03:39:33 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.147 2009/01/18 20:44:45 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -107,7 +107,7 @@ typedef enum
107107
DO_PROCLANG,
108108
DO_CAST,
109109
DO_TABLE_DATA,
110-
DO_TABLE_TYPE,
110+
DO_DUMMY_TYPE,
111111
DO_TSPARSER,
112112
DO_TSDICT,
113113
DO_TSTEMPLATE,

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.23 2009/01/01 17:23:54 momjian Exp $
12+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.24 2009/01/18 20:44:45 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -22,7 +22,9 @@ static const char *modulename = gettext_noop("sorter");
2222
* Sort priority for object types when dumping a pre-7.3 database.
2323
* Objects are sorted by priority levels, and within an equal priority level
2424
* by OID. (This is a relatively crude hack to provide semi-reasonable
25-
* behavior for old databases without full dependency info.)
25+
* behavior for old databases without full dependency info.) Note: text
26+
* search and foreign-data objects can't really happen here, so the rather
27+
* bogus priorities for them don't matter.
2628
*/
2729
static const int oldObjectTypePriority[] =
2830
{
@@ -45,7 +47,7 @@ static const int oldObjectTypePriority[] =
4547
2, /* DO_PROCLANG */
4648
2, /* DO_CAST */
4749
9, /* DO_TABLE_DATA */
48-
7, /* DO_TABLE_TYPE */
50+
7, /* DO_DUMMY_TYPE */
4951
3, /* DO_TSPARSER */
5052
4, /* DO_TSDICT */
5153
3, /* DO_TSTEMPLATE */
@@ -71,25 +73,25 @@ static const int newObjectTypePriority[] =
7173
7, /* DO_OPCLASS */
7274
7, /* DO_OPFAMILY */
7375
9, /* DO_CONVERSION */
74-
10, /* DO_TABLE */
75-
12, /* DO_ATTRDEF */
76-
17, /* DO_INDEX */
77-
18, /* DO_RULE */
78-
19, /* DO_TRIGGER */
79-
16, /* DO_CONSTRAINT */
80-
20, /* DO_FK_CONSTRAINT */
76+
16, /* DO_TABLE */
77+
18, /* DO_ATTRDEF */
78+
23, /* DO_INDEX */
79+
24, /* DO_RULE */
80+
25, /* DO_TRIGGER */
81+
22, /* DO_CONSTRAINT */
82+
26, /* DO_FK_CONSTRAINT */
8183
2, /* DO_PROCLANG */
8284
8, /* DO_CAST */
83-
13, /* DO_TABLE_DATA */
84-
11, /* DO_TABLE_TYPE */
85-
5, /* DO_TSPARSER */
86-
6, /* DO_TSDICT */
87-
5, /* DO_TSTEMPLATE */
88-
7, /* DO_TSCONFIG */
89-
3, /* DO_FDW */
90-
4, /* DO_FOREIGN_SERVER */
91-
14, /* DO_BLOBS */
92-
15 /* DO_BLOB_COMMENTS */
85+
19, /* DO_TABLE_DATA */
86+
17, /* DO_DUMMY_TYPE */
87+
10, /* DO_TSPARSER */
88+
12, /* DO_TSDICT */
89+
11, /* DO_TSTEMPLATE */
90+
13, /* DO_TSCONFIG */
91+
14, /* DO_FDW */
92+
15, /* DO_FOREIGN_SERVER */
93+
20, /* DO_BLOBS */
94+
21 /* DO_BLOB_COMMENTS */
9395
};
9496

9597

@@ -1102,9 +1104,9 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
11021104
"TABLE DATA %s (ID %d OID %u)",
11031105
obj->name, obj->dumpId, obj->catId.oid);
11041106
return;
1105-
case DO_TABLE_TYPE:
1107+
case DO_DUMMY_TYPE:
11061108
snprintf(buf, bufsize,
1107-
"TABLE TYPE %s (ID %d OID %u)",
1109+
"DUMMY TYPE %s (ID %d OID %u)",
11081110
obj->name, obj->dumpId, obj->catId.oid);
11091111
return;
11101112
case DO_TSPARSER:

0 commit comments

Comments
 (0)