-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Code of Conduct
- I agree to follow Django's Code of Conduct
Feature Description
A new pair of contrib.postgres operations to allow adding and dropping unique indexes using PostgreSQL's CONCURRENTLY option.
Problem
Django supports unique constraints via UniqueConstraints in a model’s Meta.constraints. Some of these constraints are implemented as unique indexes using CREATE UNIQUE INDEX, and can make use of the CONCURRENTLY option to avoid locking the table.
Currently, only Index objects in Meta.indexes can use AddIndexConcurrently and RemoveIndexConcurrently. Unique constraints in Meta.constraints do not have an equivalent mechanism, even when they are indexes behind the hood and could safely support CONCURRENTLY.
Request or proposal
proposal
Additional Details
Not all UniqueConstraints are implemented as indexes. Constraints defining fields, and none of includes, condition, or opclasses use ALTER TABLE ... ADD CONSTRAINT (source) while the unique constraints defining expressions or any of includes, condition, opclasses use CREATE UNIQUE INDEX.
The CONCURRENTLY option only applies to constraints backed by CREATE UNIQUE INDEX.
Implementation Suggestions
Introduce AddConstraintConcurrently and RemoveConstraintConcurrently:
- If a
UniqueConstraintis implemented viaCREATE UNIQUE INDEX, these operations add theCONCURRENTLYkeyword. - Otherwise, they behave like the standard
AddConstraintandRemoveConstraint.
A proof of concept PR demonstrates feasibility.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status