-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1104] YSQL: ALTER TABLE ADD PRIMARY KEY
Summary: Enables `ALTER TABLE ... ADD PRIMARY KEY (...)` syntax, allowing adding a primary key to a table that had none defined previously. ## Description Since the primary key is an intrinsic part of a DocDB table, we cannot literally "add" one to an existing table. Instead, this is implemented by renaming an old table, creating a new one in its stead, migrating data, and dropping an old table. All of this is performed as a single DDL transaction, so failure on any step would roll back the whole thing. Operation is logically divided onto the following phases: 1. Rename an old table 2. Create a replacement table 3. Copy CHECK and FK constraints 4. Copy table content (i.e. data itself). 5. Copy indexes (renaming old indexes in the process because of name conflicts) 6. Migrate sequences owned by old table 7. Copy triggers 8. Drop an old table ## Known limitations: * The following cases are not supported as of now: * Colocated tables (including tablegroups). * Partitioned tables and table partitions. * Table having rules. * `ALTER TABLE ADD CONSTRAINT PK USING INDEX` * If the table was created using `WITH (table_old = x)` (beta feature), that OID is lost without notice. * There are minor mismatches between YB and PG when migrating data fails (`SQLSTATE` is matching): * Null value in PK column * Duplicate PK --- Resolves #1104 and #6585 Test Plan: ybd --java-test org.yb.pgsql.TestPgAlterTableAddPrimaryKey ybd --java-test org.yb.pgsql.TestPgAlterTable#testRenameAndRecreate Reviewers: neil, nicolas, dmitry, mihnea Reviewed By: dmitry, mihnea Subscribers: dsrinivasan, zyu, bogdan, yql Differential Revision: https://phabricator.dev.yugabyte.com/D10057
- Loading branch information
1 parent
86e8385
commit 9d94a97
Showing
17 changed files
with
2,197 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.