Skip to content

Commit ca27a84

Browse files
committed
Stabilize pg_dump output order for similarly-named triggers and policies.
The code only compared two triggers' names and namespaces (the latter being the owning table's schema). This could result in falling back to an OID-based sort of similarly-named triggers on different tables. We prefer to avoid that, so add a comparison of the table names too. (The sort order is thus table namespace, trigger name, table name, which is a bit odd, but it doesn't seem worth contorting the code to work around that.) Likewise for policy objects, in 9.5 and up. Complaint and fix by Benjie Gillam. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAMThMzEEt2mvBbPgCaZ1Ap1N-moGn=Edxmadddjq89WG4NpPtQ@mail.gmail.com
1 parent 5a29674 commit ca27a84

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ DOTypeNameCompare(const void *p1, const void *p2)
165165
FuncInfo *fobj2 = *(FuncInfo *const *) p2;
166166
int i;
167167

168+
/* Sort by number of arguments, then argument type names */
168169
cmpval = fobj1->nargs - fobj2->nargs;
169170
if (cmpval != 0)
170171
return cmpval;
@@ -203,10 +204,33 @@ DOTypeNameCompare(const void *p1, const void *p2)
203204
AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
204205
AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
205206

207+
/* Sort by attribute number */
206208
cmpval = (adobj1->adnum - adobj2->adnum);
207209
if (cmpval != 0)
208210
return cmpval;
209211
}
212+
else if (obj1->objType == DO_POLICY)
213+
{
214+
PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
215+
PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
216+
217+
/* Sort by table name (table namespace was considered already) */
218+
cmpval = strcmp(pobj1->poltable->dobj.name,
219+
pobj2->poltable->dobj.name);
220+
if (cmpval != 0)
221+
return cmpval;
222+
}
223+
else if (obj1->objType == DO_TRIGGER)
224+
{
225+
TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
226+
TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
227+
228+
/* Sort by table name (table namespace was considered already) */
229+
cmpval = strcmp(tobj1->tgtable->dobj.name,
230+
tobj2->tgtable->dobj.name);
231+
if (cmpval != 0)
232+
return cmpval;
233+
}
210234

211235
/* Usually shouldn't get here, but if we do, sort by OID */
212236
return oidcmp(obj1->catId.oid, obj2->catId.oid);

0 commit comments

Comments
 (0)