postgresql/src/backend/commands
Alvaro Herrera 72cf7f310c Fix ALTER TABLE .. ATTACH PARTITION ... DEFAULT
If the table being attached contained values that contradict the default
partition's partition constraint, it would fail to complain, because
CommandCounterIncrement changes in 4dba331cb3 coupled with some bogus
coding in the existing ValidatePartitionConstraints prevented the
partition constraint from being validated after all -- or rather, it
caused to constraint to become an empty one, always succeeding.

Fix by not re-reading the OID of the default partition in
ATExecAttachPartition.  To forestall similar problems, revise the
existing code:
* rename routine from ValidatePartitionConstraints() to
  QueuePartitionConstraintValidation, to better represent what it
  actually does.
* add an Assert() to make sure that when queueing a constraint for a
  partition we're not overwriting a constraint previously queued.
* add an Assert() that we don't try to invoke the special-purpose
  validation of the default partition when attaching the default
  partition itself.

While at it, change some loops to obtain partition OIDs from
partdesc->oids rather than find_all_inheritors; reduce the lock level
of partitions being scanned from AccessExclusiveLock to ShareLock;
rewrite QueuePartitionConstraintValidation in a recursive fashion rather
than repetitive.

Author: Álvaro Herrera.  Tests written by Amit Langote
Reported-by: Rushabh Lathia
Diagnosed-by: Kyotaro HORIGUCHI, who also provided the initial fix.
Reviewed-by: Kyotaro HORIGUCHI, Amit Langote, Jeevan Ladhe
Discussion: https://postgr.es/m/CAGPqQf0W+v-Ci_qNV_5R3A=Z9LsK4+jO7LzgddRncpp_rrnJqQ@mail.gmail.com
2018-04-11 15:32:46 -03:00
..
aggregatecmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
alter.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
amcmds.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
analyze.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
async.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
cluster.c Combine options for RangeVarGetRelidExtended() into a flags argument. 2018-03-30 17:05:16 -07:00
collationcmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
comment.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
constraint.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
conversioncmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
copy.c Allow insert and update tuple routing and COPY for foreign tables. 2018-04-06 19:22:03 -04:00
createas.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
dbcommands.c Rename TransactionChain functions 2018-03-16 13:18:06 -04:00
define.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
discard.c Rename TransactionChain functions 2018-03-16 13:18:06 -04:00
dropcmds.c Add prokind column, replacing proisagg and proiswindow 2018-03-02 13:48:33 -05:00
event_trigger.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
explain.c Fix IndexOnlyScan counter for heap fetches in parallel mode 2018-04-10 15:56:15 -03:00
extension.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
foreigncmds.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
functioncmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
indexcmds.c Temporary revert 5c6110c6a9 2018-04-11 19:32:19 +03:00
lockcmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
Makefile Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
matview.c Indexes with INCLUDE columns and their support in B-tree 2018-04-07 23:00:39 +03:00
opclasscmds.c Support all SQL:2011 options for window frame clauses. 2018-02-07 00:06:56 -05:00
operatorcmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
policy.c Rename MemoryContextCopySetIdentifier() for clarity 2018-04-06 12:37:54 -04:00
portalcmds.c Rename TransactionChain functions 2018-03-16 13:18:06 -04:00
prepare.c MERGE SQL Command following SQL:2016 2018-04-03 09:28:16 +01:00
proclang.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
publicationcmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
schemacmds.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
seclabel.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
sequence.c Combine options for RangeVarGetRelidExtended() into a flags argument. 2018-03-30 17:05:16 -07:00
statscmds.c Fix bogus Name assignment in CreateStatistics 2018-03-06 13:20:40 -03:00
subscriptioncmds.c Split the SetSubscriptionRelState function into two 2018-04-06 10:00:26 -04:00
tablecmds.c Fix ALTER TABLE .. ATTACH PARTITION ... DEFAULT 2018-04-11 15:32:46 -03:00
tablespace.c Refactor dir/file permissions 2018-04-07 17:45:39 -04:00
trigger.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
tsearchcmds.c Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
typecmds.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
user.c Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
vacuum.c Merge catalog/pg_foo_fn.h headers back into pg_foo.h headers. 2018-04-08 14:35:29 -04:00
vacuumlazy.c Further cleanup of client dependencies on src/include/catalog headers. 2018-04-09 14:39:58 -04:00
variable.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
view.c Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00