Skip to content

Commit da5cd7a

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 7ab7c5c commit da5cd7a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ DOTypeNameCompare(const void *p1, const void *p2)
298298
FuncInfo *fobj2 = *(FuncInfo *const *) p2;
299299
int i;
300300

301+
/* Sort by number of arguments, then argument type names */
301302
cmpval = fobj1->nargs - fobj2->nargs;
302303
if (cmpval != 0)
303304
return cmpval;
@@ -336,10 +337,22 @@ DOTypeNameCompare(const void *p1, const void *p2)
336337
AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
337338
AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
338339

340+
/* Sort by attribute number */
339341
cmpval = (adobj1->adnum - adobj2->adnum);
340342
if (cmpval != 0)
341343
return cmpval;
342344
}
345+
else if (obj1->objType == DO_TRIGGER)
346+
{
347+
TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
348+
TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
349+
350+
/* Sort by table name (table namespace was considered already) */
351+
cmpval = strcmp(tobj1->tgtable->dobj.name,
352+
tobj2->tgtable->dobj.name);
353+
if (cmpval != 0)
354+
return cmpval;
355+
}
343356

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

0 commit comments

Comments
 (0)