postgres/src/backend/commands
Tom Lane a54faa6591 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:28 -04:00
..
aggregatecmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
alter.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
analyze.c Fix misestimation of n_distinct for a nearly-unique column with many nulls. 2016-08-07 18:52:02 -04:00
async.c Improve LISTEN startup time when there are many unread notifications. 2015-09-30 23:32:23 -04:00
cluster.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
collationcmds.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
comment.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
constraint.c Fix incorrect checking of deferred exclusion constraint after a HOT update. 2015-05-11 12:25:28 -04:00
conversioncmds.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
copy.c Be more careful to not lose sync in the FE/BE protocol. 2015-02-02 17:09:35 +02:00
createas.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
dbcommands.c Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE. 2014-11-04 13:24:17 -05:00
define.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
discard.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00
dropcmds.c Don't trash input list structure in does_not_exist_skipping(). 2012-11-08 11:34:37 -05:00
explain.c Fix inappropriate printing of never-measured times in EXPLAIN. 2016-08-12 12:13:04 -04:00
extension.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
foreigncmds.c adjust ACL owners for REASSIGN and ALTER OWNER TO 2015-12-21 19:16:15 -03:00
functioncmds.c Fix pg_get_functiondef() to print a function's LEAKPROOF property. 2015-05-28 11:24:37 -04:00
indexcmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
lockcmds.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
Makefile Restructure SELECT INTO's parsetree representation into CreateTableAsStmt. 2012-03-19 21:38:12 -04:00
opclasscmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
operatorcmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
portalcmds.c Fix subtransaction cleanup after an outer-subtransaction portal fails. 2015-09-04 13:36:50 -04:00
prepare.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
proclang.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
schemacmds.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
seclabel.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
sequence.c Reconsider when to wait for WAL flushes/syncrep during commit. 2015-02-26 12:50:07 +01:00
tablecmds.c Fix two bugs in merging of inherited CHECK constraints. 2016-10-08 19:29:28 -04:00
tablespace.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
trigger.c Fix column-privilege leak in error-message paths 2015-01-28 12:32:56 -05:00
tsearchcmds.c Fix REASSIGN OWNED for text search objects 2014-07-15 13:24:07 -04:00
typecmds.c Rework internals of changing a type's ownership 2015-12-21 19:49:15 -03:00
user.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00
vacuum.c Fetch XIDs atomically during vac_truncate_clog(). 2016-05-24 15:47:51 -04:00
vacuumlazy.c Fix VACUUM_TRUNCATE_LOCK_WAIT_INTERVAL 2016-09-09 11:45:40 +01:00
variable.c Reject out-of-range numeric timezone specifications. 2014-07-21 22:41:30 -04:00
view.c Remove tabs after spaces in C comments 2014-05-06 11:26:27 -04:00