postgres.git / summary / log / commit / refs

commit    9affed26349acafb42471de34f37dc06b1a3879e
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Commit:   Noah Misch <noah@leadboat.com>
Date:     Mon Nov 04 18:30:30 2024 +0000
First released in: 13.22, 14.19, 15.14, 16.10, 17.6

    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 350e6b8ea86c22c0b95c2e32a4e8d109255b5596 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


src/bin/pg_dump/pg_dump_sort.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index 523a19c1557..0b21497a72e 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -291,6 +291,17 @@ DOTypeNameCompare(const void *p1, const void *p2) if (cmpval != 0) return cmpval; } + else if (obj1->objType == DO_RULE) + { + RuleInfo *robj1 = *(RuleInfo *const *) p1; + RuleInfo *robj2 = *(RuleInfo *const *) p2; + + /* Sort by table name (table namespace was considered already) */ + cmpval = strcmp(robj1->ruletable->dobj.name, + robj2->ruletable->dobj.name); + if (cmpval != 0) + return cmpval; + } else if (obj1->objType == DO_TRIGGER) { TriggerInfo *tobj1 = *(TriggerInfo *const *) p1; [parent: c1984be23cdc]