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

[YSQL] ALTER TABLE ADD COLUMN ... UNIQUE doesn't work #6985

Closed
frozenspider opened this issue Jan 25, 2021 · 1 comment
Closed

[YSQL] ALTER TABLE ADD COLUMN ... UNIQUE doesn't work #6985

frozenspider opened this issue Jan 25, 2021 · 1 comment
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects

Comments

@frozenspider
Copy link
Contributor

frozenspider commented Jan 25, 2021

Jira Link: DB-1814

postgres=# CREATE TABLE test(id int PRIMARY KEY);
CREATE TABLE

postgres=# ALTER TABLE test ADD COLUMN user_id BIGINT NULL UNIQUE;
ERROR:  This ALTER TABLE command is not yet supported.

postgres=# ALTER TABLE test ADD COLUMN user_id BIGINT NULL;
ALTER TABLE

postgres=# CREATE UNIQUE INDEX ON test (user_id);
CREATE INDEX

postgres=# \d test
                Table "public.test"
 Column  |  Type   | Collation | Nullable | Default
---------+---------+-----------+----------+---------
 id      | integer |           | not null |
 user_id | bigint  |           |          |
Indexes:
    "test_pkey" PRIMARY KEY, lsm (id HASH)
    "test_user_id_idx" UNIQUE, lsm (user_id HASH)

This is surprising given that we support both adding columns and creating unique indexes when they're issued separately.

@frozenspider frozenspider added kind/enhancement This is an enhancement of an existing feature area/ysql Yugabyte SQL (YSQL) labels Jan 25, 2021
@frozenspider frozenspider added this to Backlog in YSQL via automation Jan 25, 2021
@frozenspider frozenspider assigned frozenspider and unassigned m-iancu Jan 25, 2021
YSQL automation moved this from Backlog to Done Feb 26, 2021
@frozenspider
Copy link
Contributor Author

Simplest case (nullable, no defaults, no CHECK constraints, no FKs) was implemented in ce46d1a, but the general case is still NYI - we need to be able to rollback DocDB DDL changes for that.

@frozenspider frozenspider reopened this Feb 26, 2021
YSQL automation moved this from Done to In progress Feb 26, 2021
@frozenspider frozenspider moved this from In progress to To do in YSQL Feb 26, 2021
@frozenspider frozenspider moved this from To do to Backlog in YSQL Feb 26, 2021
polarweasel pushed a commit to lizayugabyte/yugabyte-db that referenced this issue Mar 9, 2021
Summary:
For now, DocDB doesn't roll back added columns in case of transaction failure, which makes adding a constrained column problematic.
However, supporting adding a trivial UNIQUE column is still beneficial for supporting auto-generated migrations (e.g. this syntax is used by Dart/Aqueduct).

For that, we change the way we do `YBCPrepareAlterTable`/`YBCExecAlterTable` so that DocDB's part of `ALTER TABLE` kicks in before we try to create an index - because an indexed column might not be there yet.

Note that we still do not guarantee consistency in an odd case of the Postgres process crashing between adding a column and adding an index.

---

Resolves yugabyte#6985

Test Plan: ybd --java-test org.yb.pgsql.TestPgAlterTable

Reviewers: dmitry, mihnea, jason, neil

Reviewed By: jason

Subscribers: yql

Differential Revision: https://phabricator.dev.yugabyte.com/D10546
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Jun 9, 2022
@yugabyte-ci yugabyte-ci assigned tverona1 and unassigned frozenspider Feb 28, 2023
@fizaaluthra fizaaluthra self-assigned this Jun 20, 2024
YSQL automation moved this from Backlog to Done Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
Status: Done
YSQL
  
Done
Development

No branches or pull requests

5 participants