-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Description
Description
Full support for altering primary key. The current "alter-primary-key" can only be treated as a workaround: it is with a lot of limitations and the semantic of it is confusing:
If an existing table defined a single integer column as its primary key, the primary key cannot be altered.
Altering integer primary key for is challenging in TiDB because it is special: the row id of the data is mapped from the integers, so it determines where the actual row data is stored. When Cluster Index is supported, such limitation will be extended to all explicit primary keys.
Category
Feature, Usability
Value
The ability to change the primary key is an important feature of a maintainable database. Users usually starts their deployments in a simple scenario, and with the growth of the application there will be likely the requirement to change their primary keys.
Workload Estimation
Seems the only way to implement this feature is the 'COPY' algorithm, if we want to make it available online:
- Create a hidden table that is with the changed(new) primary key.
- All updates of the existing table are applied to the changed table as well.
- Backfill all rows from existing table to the new table.
75