postgresql/src/backend
Tom Lane e55a946a81 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>
2016-10-08 19:29:27 -04:00
..
access Extend framework from commit 53be0b1ad to report latch waits. 2016-10-04 11:01:42 -04:00
bootstrap Fix a bunch of places that called malloc and friends with no NULL check. 2016-08-30 18:22:43 -04:00
catalog Fix two bugs in merging of inherited CHECK constraints. 2016-10-08 19:29:27 -04:00
commands Fix two bugs in merging of inherited CHECK constraints. 2016-10-08 19:29:27 -04:00
executor Extend framework from commit 53be0b1ad to report latch waits. 2016-10-04 11:01:42 -04:00
foreign Remove GetUserMappingId() and GetUserMappingById(). 2016-07-22 11:32:23 -04:00
lib Clarify the new Red-Black post-order traversal code a bit. 2016-09-04 15:02:06 +03:00
libpq Extend framework from commit 53be0b1ad to report latch waits. 2016-10-04 11:01:42 -04:00
main Repair a bit of pgindent damage. 2016-06-09 18:09:17 -04:00
nodes Add debugging aid "bmsToString(Bitmapset *bms)". 2016-09-16 09:36:24 -04:00
optimizer Disallow pushing volatile quals past set-returning functions. 2016-09-27 18:43:36 -04:00
parser Add ALTER EXTENSION ADD/DROP ACCESS METHOD, and use it in pg_upgrade. 2016-10-02 14:31:28 -04:00
po Translation updates 2016-08-08 11:08:00 -04:00
port Fix fallback implementation of pg_atomic_write_u32(). 2016-10-07 16:55:15 -07:00
postmaster Re-alphabetize #include directives. 2016-10-05 08:24:25 -04:00
regex Make locale-dependent regex character classes work for large char codes. 2016-09-05 17:06:29 -04:00
replication libpqwalreceiver needs to link with libintl when using --enable-nls. 2016-10-07 21:12:25 -04:00
rewrite Improve parser's and planner's handling of set-returning functions. 2016-09-13 13:54:24 -04:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Fix fallback implementation of pg_atomic_write_u32(). 2016-10-07 16:55:15 -07:00
tcop Add location field to DefElem 2016-09-06 12:00:00 -04:00
tsearch Add macros to make AllocSetContextCreate() calls simpler and safer. 2016-08-27 17:50:38 -04:00
utils Remove bogus mapping from UTF-8 to SJIS conversion table. 2016-10-07 23:56:42 +03:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Refer to OS X as "macOS", except for the port name which is still "darwin". 2016-09-25 15:40:57 -04:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00