| Goal | This query identifies superfluous UNIQUE constraints where the constraint is logically subsumed by a more general EXCLUDE constraint on the same table. It targets cases where the set of columns in a UNIQUE or PRIMARY KEY constraint is a subset of (or equal to) the columns in an EXCLUDE constraint, provided the EXCLUDE constraint uses the equality operator (=) for those same columns. In this scenario, the EXCLUDE constraint already enforces uniqueness as part of its more complex logic, rendering the separate UNIQUE constraint redundant. Eliminating this duplication improves schema clarity and removes an unnecessary constraint check. |
| Type | Problem detection (Each row in the result could represent a flaw in the design) |
| Reliability | Medium (Medium number of false-positive results) |
| License | MIT License |
| Fixing Suggestion | If a uniqueness constraint is a special case of the exclude constraint, then drop the uniqueness constraint. For instance, in the following case the UNIQUE constraint is redundant: EXCLUDE USING gist (worker_id WITH =, project_id WITH =, tstzrange(begin_time, end_time, '[)'::text) WITH &&) UNIQUE (begin_time, worker_id, project_id) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
This query belongs to the following collections:
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
This query is classified under the following categories:
| Name | Description |
|---|---|
| Uniqueness | Queries of this category provide information about uniqueness constraints (PRIMARY KEY, UNIQUE, EXCLUDE) as well as unique indexes. |
| Validity and completeness | Queries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness). |