cockroach
cockroach copied to clipboard
sql: ALTER TABLE ... ADD CONSTRAINT should validate existing rows
Currently, check constraints and FK constraints are added in the Unvalidated state and not assumed to hold for existing rows in the table. Constraints can be validated later using VALIDATE CONSTRAINT. The preferable behavior would be to validate the new constraint on existing rows (asynchronously, after the transaction has committed). This would match the default behavior in Postgres, which also validates the existing rows up front (unless otherwise specified, using NOT VALID).
#32504 (not yet merged) implements this change for adding a check constraint. The plan is to handle FK constraints similarly.
Closing in favor of #34238 which is tracking all related work.