Skip to content

Full support for altering primary key #18090

@scsldb

Description

@scsldb

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:

  1. Create a hidden table that is with the changed(new) primary key.
  2. All updates of the existing table are applied to the changed table as well.
  3. Backfill all rows from existing table to the new table.

75

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibility-mysql80This is a compatibility issue with MySQL 8.0(but NOT 5.7)feature/acceptedThis feature request is accepted by product managerspriority/P1The issue has P1 priority.type/compatibilitytype/feature-requestCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions