postgresql/src/include/catalog
Tom Lane 17b7c302b5 Fully enforce uniqueness of constraint names.
It's been true for a long time that we expect names of table and domain
constraints to be unique among the constraints of that table or domain.
However, the enforcement of that has been pretty haphazard, and it missed
some corner cases such as creating a CHECK constraint and then an index
constraint of the same name (as per recent report from André Hänsel).
Also, due to the lack of an actual unique index enforcing this, duplicates
could be created through race conditions.

Moreover, the code that searches pg_constraint has been quite inconsistent
about how to handle duplicate names if one did occur: some places checked
and threw errors if there was more than one match, while others just
processed the first match they came to.

To fix, create a unique index on (conrelid, contypid, conname).  Since
either conrelid or contypid is zero, this will separately enforce
uniqueness of constraint names among constraints of any one table and any
one domain.  (If we ever implement SQL assertions, and put them into this
catalog, more thought might be needed.  But it'd be at least as reasonable
to put them into a new catalog; having overloaded this one catalog with
two kinds of constraints was a mistake already IMO.)  This index can replace
the existing non-unique index on conrelid, though we need to keep the one
on contypid for query performance reasons.

Having done that, we can simplify the logic in various places that either
coped with duplicates or neglected to, as well as potentially improve
lookup performance when searching for a constraint by name.

Also, as per our usual practice, install a preliminary check so that you
get something more friendly than a unique-index violation report in the
case complained of by André.  And teach ChooseIndexName to avoid choosing
autogenerated names that would draw such a failure.

While it's not possible to make such a change in the back branches,
it doesn't seem quite too late to put this into v11, so do so.

Discussion: https://postgr.es/m/0c1001d4428f$0942b430$1bc81c90$@webkr.de
2018-09-04 13:45:35 -04:00
..
.gitignore Replace our traditional initial-catalog-data format with a better design. 2018-04-08 13:17:27 -04:00
Makefile Replace our traditional initial-catalog-data format with a better design. 2018-04-08 13:17:27 -04:00
binary_upgrade.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
catalog.h Further cleanup of client dependencies on src/include/catalog headers. 2018-04-09 14:39:58 -04:00
catversion.h Fully enforce uniqueness of constraint names. 2018-09-04 13:45:35 -04:00
dependency.h Local partitioned indexes 2018-01-19 11:49:22 -03:00
duplicate_oids Fix duplicate_oids and unused_oids so user needn't cd to catalog dir. 2018-04-26 11:20:01 -04:00
genbki.h Replace our traditional initial-catalog-data format with a better design. 2018-04-08 13:17:27 -04:00
heap.h Error position support for defaults and check constraints 2018-08-30 08:20:23 +02:00
index.h Allow UNIQUE indexes on partitioned tables 2018-02-19 17:40:00 -03:00
indexing.h Fully enforce uniqueness of constraint names. 2018-09-04 13:45:35 -04:00
namespace.h Make autovacuum more aggressive to remove orphaned temp tables 2018-08-13 11:49:04 +02:00
objectaccess.h Fix typo 2018-03-07 09:02:57 -05:00
objectaddress.h Replace AclObjectKind with ObjectType 2018-01-19 14:01:15 -05:00
opfam_internal.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
partition.h Reorganize partitioning code 2018-04-14 21:12:14 -03:00
pg_aggregate.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_aggregate.h Improve spelling of new FINALFUNC_MODIFY aggregate attribute. 2018-05-21 11:41:42 -04:00
pg_am.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_am.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_amop.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_amop.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_amproc.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_amproc.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_attrdef.h Add some not null constraints to catalogs 2018-08-27 16:21:23 +02:00
pg_attribute.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_auth_members.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_authid.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_authid.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_cast.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_cast.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_class.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_class.h Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
pg_collation.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_collation.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_constraint.h Fully enforce uniqueness of constraint names. 2018-09-04 13:45:35 -04:00
pg_control.h Revert "Allow on-line enabling and disabling of data checksums" 2018-04-09 19:03:42 +02:00
pg_conversion.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_database.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_database.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_db_role_setting.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_default_acl.h Add some not null constraints to catalogs 2018-08-27 16:21:23 +02:00
pg_depend.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_description.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_enum.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_event_trigger.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_extension.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_foreign_data_wrapper.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_foreign_server.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_foreign_table.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_index.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_inherits.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_init_privs.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_language.dat Cosmetic improvement: use BKI_DEFAULT and BKI_LOOKUP in pg_language. 2018-04-29 13:26:26 -04:00
pg_language.h Cosmetic improvement: use BKI_DEFAULT and BKI_LOOKUP in pg_language. 2018-04-29 13:26:26 -04:00
pg_largeobject.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_largeobject_metadata.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_namespace.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_namespace.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_opclass.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_opclass.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_operator.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_operator.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_opfamily.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_opfamily.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_partitioned_table.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_pltemplate.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_pltemplate.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_policy.h Add some not null constraints to catalogs 2018-08-27 16:21:23 +02:00
pg_proc.dat Fix argument of pg_create_logical_replication_slot for slot name 2018-07-13 09:32:12 +09:00
pg_proc.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_publication.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_publication_rel.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_range.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_range.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_replication_origin.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_rewrite.h Add some not null constraints to catalogs 2018-08-27 16:21:23 +02:00
pg_seclabel.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_sequence.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_shdepend.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_shdescription.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_shseclabel.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_statistic.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_statistic_ext.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_subscription.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_subscription_rel.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_tablespace.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_tablespace.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_transform.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_trigger.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_config.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_config.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_config_map.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_config_map.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_dict.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_dict.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_parser.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_parser.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_template.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_ts_template.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_type.dat Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
pg_type.h Update a couple of long-obsolete comments in pg_type.h. 2018-05-26 13:47:26 -04:00
pg_user_mapping.h Improve consistency of comments in system catalog headers. 2018-04-19 17:14:09 -04:00
reformat_dat_file.pl Don't fall off the end of perl functions 2018-05-27 09:08:42 -04:00
storage.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
storage_xlog.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
toasting.h Add toast tables to most system catalogs 2018-07-20 07:43:41 +09:00
unused_oids Assorted minor cleanups for bootstrap-data Perl scripts. 2018-05-19 16:04:47 -04:00