pgsql: Fix two bugs in merging of inherited CHECK constraints.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix two bugs in merging of inherited CHECK constraints.
Дата
Msg-id E1bt13u-0000w3-R2@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix two bugs in merging of inherited CHECK constraints.

Historically, we've allowed users to add a CHECK constraint to a child
table and then add an identical CHECK constraint to the parent.  This
results in "merging" the two constraints so that the pre-existing
child constraint ends up with both conislocal = true and coninhcount > 0.
However, if you tried to do it in the other order, you got a duplicate
constraint error.  This is problematic for pg_dump, which needs to issue
separated ADD CONSTRAINT commands in some cases, but has no good way to
ensure that the constraints will be added in the required order.
And it's more than a bit arbitrary, too.  The goal of complaining about
duplicated ADD CONSTRAINT commands can be served if we reject the case of
adding a constraint when the existing one already has conislocal = true;
but if it has conislocal = false, let's just make the ADD CONSTRAINT set
conislocal = true.  In this way, either order of adding the constraints
has the same end result.

Another problem was that the code allowed creation of a parent constraint
marked convalidated that is merged with a child constraint that is
!convalidated.  In this case, an inheritance scan of the parent table could
emit some rows violating the constraint condition, which would be an
unexpected result given the marking of the parent constraint as validated.
Hence, forbid merging of constraints in this case.  (Note: valid child and
not-valid parent seems fine, so continue to allow that.)

Per report from Benedikt Grundmann.  Back-patch to 9.2 where we introduced
possibly-not-valid check constraints.  The second bug obviously doesn't
apply before that, and I think the first doesn't either, because pg_dump
only gets into this situation when dealing with not-valid constraints.

Report: <CADbMkNPT-Jz5PRSQ4RbUASYAjocV_KHUWapR%2Bg8fNvhUAyRpxA%40mail.gmail.com>
Discussion: <22108.1475874586@sss.pgh.pa.us>

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/a54faa6591df7a1ea15078c4979f882a596ae480

Modified Files
--------------
src/backend/catalog/heap.c                 | 40 +++++++++++++++++++-----
src/backend/commands/tablecmds.c           | 13 +++++++-
src/test/regress/expected/inherit.out      | 50 ++++++++++++++++++++++++++++++
src/test/regress/expected/sanity_check.out |  4 ++-
src/test/regress/sql/inherit.sql           | 39 +++++++++++++++++++++++
5 files changed, 136 insertions(+), 10 deletions(-)


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix two bugs in merging of inherited CHECK constraints.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix two bugs in merging of inherited CHECK constraints.