yugabyte-db icon indicating copy to clipboard operation
yugabyte-db copied to clipboard

[YSQL] Creating unique constraint must warn that it is unsafe in presence of concurrent DML operations

Open deeps1991 opened this issue 2 years ago • 0 comments

Jira Link: DB-2963

Description

Currently, if the user tries to create a unique constraint in the following manner:

ALTER TABLE test ADD CONSTRAINT test_unique_constraint UNIQUE(unique_field);

This initiates creation of a unique index to back up the unique constraint. However by default, this is a nonconcurrent index build. This means it may not take into account any concurrently occurring writes. It would be useful to issue a NOTICE that warns that this is an unsafe operation in the presence of concurrent DML operations.

In those cases, it would be good to first create a unique index that uses online index backfill, and then create a constraint using that index.

example:

create unique index testidx on test(unique_field);
alter table test add constraint test_unique_constraint unique USING INDEX testidx;

deeps1991 avatar Jul 15 '22 17:07 deeps1991