Skip to content

Commit 350e6b8

Browse files
committed
pg_dump: provide a stable sort order for rules.
Previously, we sorted rules by schema name and then rule name; if that wasn't unique, we sorted by rule OID. This can be problematic for comparing dumps from databases with different histories, especially since certain rule names like "_RETURN" are very common. Let's make the sort key schema name, rule name, table name, which should be unique. (This is the same behavior we've long used for triggers and RLS policies.) Andreas Karlsson Discussion: https://postgr.es/m/b4e468d8-0cd6-42e6-ac8a-1d6afa6e0cf1@proxel.se
1 parent 215f7af commit 350e6b8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,17 @@ DOTypeNameCompare(const void *p1, const void *p2)
294294
if (cmpval != 0)
295295
return cmpval;
296296
}
297+
else if (obj1->objType == DO_RULE)
298+
{
299+
RuleInfo *robj1 = *(RuleInfo *const *) p1;
300+
RuleInfo *robj2 = *(RuleInfo *const *) p2;
301+
302+
/* Sort by table name (table namespace was considered already) */
303+
cmpval = strcmp(robj1->ruletable->dobj.name,
304+
robj2->ruletable->dobj.name);
305+
if (cmpval != 0)
306+
return cmpval;
307+
}
297308
else if (obj1->objType == DO_TRIGGER)
298309
{
299310
TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;

0 commit comments

Comments
 (0)