postgresql/src
Tom Lane f1ad067fc3 Sort the dependent objects before recursing in findDependentObjects().
Historically, the notices output by DROP CASCADE tended to come out
in uncertain order, and in some cases you might get different claims
about which object depends on which other one.  This is because we
just traversed the dependency tree in the order in which pg_depend
entries are seen, and nbtree has never promised anything about the
order of equal-keyed index entries.  We've put up with that for years,
hacking regression tests when necessary to prevent them from emitting
unstable output.  However, it's a problem for pending work that will
change nbtree's behavior for equal keys, as that causes unexpected
changes in the regression test results.

Hence, adjust findDependentObjects to sort the results of each
indexscan before processing them.  The sort is on descending OID of
the dependent objects, hence more or less reverse creation order.
While this rule could still result in bogus regression test failures
if an OID wraparound occurred mid-test, that seems unlikely to happen
in any plausible development or packaging-test scenario.

This is enough to ensure output stability for ordinary DROP CASCADE
commands, but not for DROP OWNED BY, because that has a different
code path with the same problem.  We might later choose to sort in
the DROP OWNED BY code as well, but this patch doesn't do so.

I've also not done anything about reverting the existing hacks to
suppress unstable DROP CASCADE output in specific regression tests.
It might be worth undoing those, but it seems like a distinct question.

The first indexscan loop in findDependentObjects is not touched,
meaning there is a hazard of unstable error reports from that too.
However, said hazard is not the fault of that code: it was designed
on the assumption that there could be at most one "owning" object
to complain about, and that assumption does not seem unreasonable.
The recent patch that added the possibility of multiple
DEPENDENCY_INTERNAL_AUTO links broke that assumption, but we should
fix that situation not band-aid around it.  That's a matter for
another patch, though.

Discussion: https://postgr.es/m/12244.1547854440@sss.pgh.pa.us
2019-01-21 13:48:14 -05:00
..
backend Sort the dependent objects before recursing in findDependentObjects(). 2019-01-21 13:48:14 -05:00
bin Revert "Fix under-quoted filename pattern in pgbench TAP test." 2019-01-21 11:28:03 -05:00
common Use perfect hashing, instead of binary search, for keyword lookup. 2019-01-09 19:47:46 -05:00
fe_utils pgbench: add \cset and \gset commands 2019-01-10 13:42:20 -03:00
include Avoid thread-safety problem in ecpglib. 2019-01-21 12:07:02 -05:00
interfaces Avoid thread-safety problem in ecpglib. 2019-01-21 12:07:02 -05:00
makefiles Ensure link commands list *.o files before LDFLAGS. 2019-01-02 13:57:54 -05:00
pl Use perfect hashing, instead of binary search, for keyword lookup. 2019-01-09 19:47:46 -05:00
port Use our own getopt() on OpenBSD. 2019-01-18 15:06:26 -05:00
template Yet further rethinking of build changes for macOS Mojave. 2018-11-02 18:54:00 -04:00
test Sort the dependent objects before recursing in findDependentObjects(). 2019-01-21 13:48:14 -05:00
timezone Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
tools Revert "Add valgrind suppressions for wcsrtombs optimizations" 2019-01-19 20:49:51 +01:00
tutorial Update copyright for 2019 2019-01-02 12:44:25 -05:00
.gitignore
DEVELOPERS
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in fix typo 2019-01-13 16:43:14 -05:00
Makefile.shlib Ensure static libraries have correct mod time even if ranlib messes it up. 2018-11-29 15:53:44 -05:00
nls-global.mk Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00