Skip to content

The SQL generated by conv to rename or reassign the primary key fails only on TiDB #60

@howyi

Description

@howyi

TiDB adopts a clustered index by default, which means it does not allow the table to exist without a PRIMARY KEY.

Because of this, any ALTER statement generated by conv that renames the primary key will result in an error at runtime. While one way to address this in TiDB is to recreate the table and migrate the data, the current conv tool only performs schema changes without manipulating actual data. Therefore, we need to determine the best approach for handling this issue.

CREATE TABLE `tbl_music` (
     `music_id` int NOT NULL COMMENT 'Unique music ID',
     `music_id2` int NOT NULL COMMENT 'Unique music ID2',
     PRIMARY KEY (`music_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='Music';

ALTER TABLE `tbl_music`
   DROP PRIMARY KEY,
   ADD PRIMARY KEY (`music_id2`);

// [HY000][8200] Unsupported drop primary key when the table is using clustered index

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions