Skip to content

Commit cc9a62c

Browse files
tglsfdcnmisch
authored andcommitted
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 This back-patches v18 commit 350e6b8 to all supported branches. The next commit will assert that pg_dump provides a stable sort order for all object types. That assertion would fail without stabilizing DO_RULE order as this commit did. Discussion: https://postgr.es/m/b4e468d8-0cd6-42e6-ac8a-1d6afa6e0cf1@proxel.se Discussion: https://postgr.es/m/20250707192654.9e.nmisch@google.com Backpatch-through: 13-17
1 parent 612f5b8 commit cc9a62c

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
@@ -238,6 +238,17 @@ DOTypeNameCompare(const void *p1, const void *p2)
238238
if (cmpval != 0)
239239
return cmpval;
240240
}
241+
else if (obj1->objType == DO_RULE)
242+
{
243+
RuleInfo *robj1 = *(RuleInfo *const *) p1;
244+
RuleInfo *robj2 = *(RuleInfo *const *) p2;
245+
246+
/* Sort by table name (table namespace was considered already) */
247+
cmpval = strcmp(robj1->ruletable->dobj.name,
248+
robj2->ruletable->dobj.name);
249+
if (cmpval != 0)
250+
return cmpval;
251+
}
241252
else if (obj1->objType == DO_TRIGGER)
242253
{
243254
TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy