github / github/gh-ost

can i add column to primary key one time

Open
#678 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
13.6k
Forks
1.4k
Avg merge
2h 31m
Merged PRs (30d)
4

Description

hello, I have a table with only primary key, I want to change table to partition table(table like below). Mysql must primary key include partition key. if I want to achive this,I have to
alter table test add unique key uk(id,dt)
alter table drop primary key,add primary key(id,dt),drop index uk
alter table add partition***
If I have a table more than 300G, it takes a really long time
In such a case, when pk or uk needs to add more column, is it possible to achive this by one alter, If not , what will be the problem? Thanks a lot for advise

CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`dt` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`c1` int(11) DEFAULT NULL,
`c2` int(11) DEFAULT NULL,
`dt` int(11) NOT NULL,
PRIMARY KEY (`id`,`dt`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.