pgsql: Sort the dependent objects before recursing infindDependentObje

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Sort the dependent objects before recursing infindDependentObje
Дата
Msg-id E1glecT-0007PU-4w@gemulon.postgresql.org
обсуждение исходный текст
Ответы Re: pgsql: Sort the dependent objects before recursing infindDependentObje  (Andres Freund <andres@anarazel.de>)
Список pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f1ad067fc3ae3d34dc6b8826913d454cc3fe354f

Modified Files
--------------
src/backend/catalog/dependency.c              | 100 ++++++++++++++++++++++----
src/test/regress/expected/alter_table.out     |   2 +-
src/test/regress/expected/create_type.out     |   8 +--
src/test/regress/expected/domain.out          |   4 +-
src/test/regress/expected/matview.out         |   8 +--
src/test/regress/expected/updatable_views.out |   4 +-
6 files changed, 98 insertions(+), 28 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Add 'id' to Acknowledgments section
Следующее
От: Andres Freund
Дата:
Сообщение: pgsql: Introduce access/{table.h, relation.h},for generic functions fr