Skip to content

Commit ee8b95f

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 1fee24a commit ee8b95f

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
@@ -257,6 +257,7 @@ DOTypeNameCompare(const void *p1, const void *p2)
257257
FuncInfo *fobj2 = *(FuncInfo *const *) p2;
258258
int i;
259259

260+
/* Sort by number of arguments, then argument type names */
260261
cmpval = fobj1->nargs - fobj2->nargs;
261262
if (cmpval != 0)
262263
return cmpval;
@@ -295,10 +296,33 @@ DOTypeNameCompare(const void *p1, const void *p2)
295296
AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
296297
AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
297298

299+
/* Sort by attribute number */
298300
cmpval = (adobj1->adnum - adobj2->adnum);
299301
if (cmpval != 0)
300302
return cmpval;
301303
}
304+
else if (obj1->objType == DO_POLICY)
305+
{
306+
PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
307+
PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
308+
309+
/* Sort by table name (table namespace was considered already) */
310+
cmpval = strcmp(pobj1->poltable->dobj.name,
311+
pobj2->poltable->dobj.name);
312+
if (cmpval != 0)
313+
return cmpval;
314+
}
315+
else if (obj1->objType == DO_TRIGGER)
316+
{
317+
TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
318+
TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
319+
320+
/* Sort by table name (table namespace was considered already) */
321+
cmpval = strcmp(tobj1->tgtable->dobj.name,
322+
tobj2->tgtable->dobj.name);
323+
if (cmpval != 0)
324+
return cmpval;
325+
}
302326

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

0 commit comments

Comments
 (0)