pg_dump: sortDumpableObjectsByTypeName() doesn't always do that - Mailing list pgsql-hackers

From Jacob Champion
Subject pg_dump: sortDumpableObjectsByTypeName() doesn't always do that
Date
Msg-id CABAq_6Hw+V-Kj7PNfD5tgOaWT_-qaYkc+SRmJkPLeUjYXLdxwQ@mail.gmail.com
Whole thread Raw
Responses Re: pg_dump: sortDumpableObjectsByTypeName() doesn't always do that
List pgsql-hackers
Hi all,

We recently ran into an issue in pg_dump that caused the initial
sort-by-name pass to return incorrect results. It doesn't seem to
affect overall correctness, since the later toposort pass takes care
of dependencies, but it does occasionally cause a spurious diff in
dump output before and after a pg_upgrade run.

The key appears to be in this comment, in pg_dump_sort.c:

/*
 * Sort by namespace. Note that all objects of the same type should
 * either have or not have a namespace link, so we needn't be fancy about
 * cases where one link is null and the other not.
 */

This doesn't appear to be correct anymore. From scanning the code, it
looks like the DO_DEFAULT_ACL type can optionally have a NULL
namespace. Even if it were correct, we can get to this part of the
code with objects of different types, as long as they share the same
sort priority (see DO_COLLATION and DO_TRANSFORM). We only ran into
this because of a bug in Greenplum that caused two types to share a
sort priority where they previously did not.

A quick and dirty patch is attached, which simply defines an ordering
between NULL and non-NULL namespaces so that quicksort behaves
rationally.

WDYT?

--Jacob

Attachment

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: Standby trying "restore_command" before local WAL
Next
From: Tom Lane
Date:
Subject: Re: pg_dump: sortDumpableObjectsByTypeName() doesn't always do that