Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: unique without index constraint not validated if it's added with drop column in one statement #99281

Closed
chengxiong-ruan opened this issue Mar 22, 2023 · 5 comments · Fixed by #99858
Assignees
Labels
branch-release-23.1 Used to mark GA and release blockers, technical advisories, and bugs for 23.1 C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. GA-blocker T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@chengxiong-ruan
Copy link
Contributor

chengxiong-ruan commented Mar 22, 2023

Describe the problem
if a UNIQUE WITHOUT INDEX constraint is added with a DROP COLUMN in one statement, the uniqueness is not vlidated.

To Reproduce

root@localhost:26257/defaultdb> create table t1 (a int, b int);
CREATE TABLE

root@localhost:26257/defaultdb> insert into t1 (a) values (1), (1);
INSERT 0 2

root@localhost:26257/defaultdb> alter table t1 drop column b, add constraint c1 unique
                             -> without index (a);
ALTER TABLE

root@localhost:26257/defaultdb> select * from t1;
  a
-----
  1
  1
(2 rows)

root@localhost:26257/defaultdb> show create table t1;
  table_name |                      create_statement
-------------+--------------------------------------------------------------
  t1         | CREATE TABLE public.t1 (
             |     a INT8 NULL,
             |     rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
             |     CONSTRAINT t1_pkey PRIMARY KEY (rowid ASC),
             |     CONSTRAINT c1 UNIQUE WITHOUT INDEX (a)
             | )

root@localhost:26257/defaultdb> insert into t1 values (1);
ERROR: duplicate key value violates unique constraint "c1"
SQLSTATE: 23505
DETAIL: Key (a)=(1) already exists.
CONSTRAINT: c1

Expected behavior
add unique constraint should fail...

Environment:

  • CockroachDB version 23.1 and master

Jira issue: CRDB-25805

@chengxiong-ruan chengxiong-ruan added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-schema-deprecated Use T-sql-foundations instead labels Mar 22, 2023
@chengxiong-ruan
Copy link
Contributor Author

chengxiong-ruan commented Mar 22, 2023

@Xiang-Gu feel free to close if this is expected which I don't think is the case.

@blathers-crl
Copy link

blathers-crl bot commented Mar 23, 2023

Hi @chengxiong-ruan, please add branch-* labels to identify which branch(es) this release-blocker affects.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@chengxiong-ruan chengxiong-ruan added branch-release-23.1 Used to mark GA and release blockers, technical advisories, and bugs for 23.1 GA-blocker and removed GA-blocker branch-release-23.1 Used to mark GA and release blockers, technical advisories, and bugs for 23.1 labels Mar 23, 2023
@blathers-crl
Copy link

blathers-crl bot commented Mar 23, 2023

Hi @chengxiong-ruan, please add branch-* labels to identify which branch(es) this release-blocker affects.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@chengxiong-ruan chengxiong-ruan added the branch-release-23.1 Used to mark GA and release blockers, technical advisories, and bugs for 23.1 label Mar 23, 2023
@chengxiong-ruan
Copy link
Contributor Author

Sorry, I touched the wrong ticket. This is still a GA blocker.

@ajwerner
Copy link
Contributor

@Xiang-Gu was saying that we are missing the rule to wait for the source index to validate the constraint to be backfilled and validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-release-23.1 Used to mark GA and release blockers, technical advisories, and bugs for 23.1 C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. GA-blocker T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants