-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Deduplicate unique indexes when altering primary key #74116
Copy link
Copy link
Closed
Labels
A-schema-changesC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-easyEasy issue to tackle, requires little or no CockroachDB experienceEasy issue to tackle, requires little or no CockroachDB experienceT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Description
Is your feature request related to a problem? Please describe.
When we alter primary key, we create a unique index to match the old primary key. However, it doest that no matter if there's already a same unique key exists or not. So we have duplicate unique indexes in this case.
--(1) create table with unique index on primary key columns
create table t (a int primary key, b int not null, unique index t_a_key (a));
--(2) alter primary key
alter table t alter primary key using columns (b);
--(3) t has duplicate unique index on column (a)
show create table t;
table_name | create_statement
-------------+---------------------------------------------
t | CREATE TABLE public.t (
| a INT8 NOT NULL,
| b INT8 NOT NULL,
| CONSTRAINT t_pkey PRIMARY KEY (b ASC),
| UNIQUE INDEX t_a_key1 (a ASC),
| UNIQUE INDEX t_a_key (a ASC),
| FAMILY "primary" (a, b)
| )Describe the solution you'd like
We make add some deduplication here.
Jira issue: CRDB-11924
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-changesC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-easyEasy issue to tackle, requires little or no CockroachDB experienceEasy issue to tackle, requires little or no CockroachDB experienceT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)