如何使用Percona的`pt-online-schema-change`工具进行`CREATE INDEX`?

时间:2022-10-06 18:46:07

How do I do a CREATE INDEX with Percona's pt-online-schema-change tool? I want to do something like:

如何使用Percona的pt-online-schema-change工具创建CREATE INDEX?我想做的事情如下:

CREATE UNIQUE INDEX idx_name ON table_name (col_1, col_2, ...) USING BTREE

CREATE UNIQUE INDEX idx_name ON table_name(col_1,col_2,...)USING BTREE

According to the documentation, I must use the --alter argument and then the appropriate ALTER TABLE statement, minus the preceding ALTER TABLE table_name phrase. However, CREATE INDEX does not start with ALTER TABLE, and the table name is embedded inside the CREATE INDEX statement. So how can I move forward?

根据文档,我必须使用--alter参数,然后使用适当的ALTER TABLE语句,减去前面的ALTER TABLE table_name短语。但是,CREATE INDEX不以ALTER TABLE开头,表名嵌入在CREATE INDEX语句中。那么我该如何前进呢?

2 个解决方案

#1


9  

According to the documentation for MySQL CREATE INDEX:

根据MySQL CREATE INDEX的文档:

CREATE INDEX is mapped to an ALTER TABLE statement to create indexes.

CREATE INDEX映射到ALTER TABLE语句以创建索引。

Thus, you can convert my example to the SQL statement:

因此,您可以将我的示例转换为SQL语句:

ALTER TABLE table_name ADD UNIQUE INDEX idx_name (col_1, col_2, ...) USING BTREE

ALTER TABLE table_name ADD UNIQUE INDEX idx_name(col_1,col_2,...)USING BTREE

Resulting in the Percona schema modification statement:

导致Percona架构修改声明:

ADD UNIQUE INDEX idx_name (col_1, col_2, ...) USING BTREE

添加UNIQUE INDEX idx_name(col_1,col_2,...)使用BTREE

#2


2  

I use this one) pt-online-schema-change --alter 'add index ix_cdate (cdate)' D=database_name,t=table_name --dry-run --critical-load Threads_running=110

我使用这个)pt-online-schema-change --alter'add index ix_cdate(cdate)'D = database_name,t = table_name --dry-run --critical-load Threads_running = 110

#1


9  

According to the documentation for MySQL CREATE INDEX:

根据MySQL CREATE INDEX的文档:

CREATE INDEX is mapped to an ALTER TABLE statement to create indexes.

CREATE INDEX映射到ALTER TABLE语句以创建索引。

Thus, you can convert my example to the SQL statement:

因此,您可以将我的示例转换为SQL语句:

ALTER TABLE table_name ADD UNIQUE INDEX idx_name (col_1, col_2, ...) USING BTREE

ALTER TABLE table_name ADD UNIQUE INDEX idx_name(col_1,col_2,...)USING BTREE

Resulting in the Percona schema modification statement:

导致Percona架构修改声明:

ADD UNIQUE INDEX idx_name (col_1, col_2, ...) USING BTREE

添加UNIQUE INDEX idx_name(col_1,col_2,...)使用BTREE

#2


2  

I use this one) pt-online-schema-change --alter 'add index ix_cdate (cdate)' D=database_name,t=table_name --dry-run --critical-load Threads_running=110

我使用这个)pt-online-schema-change --alter'add index ix_cdate(cdate)'D = database_name,t = table_name --dry-run --critical-load Threads_running = 110