Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do a `CREATE INDEX` with Percona's `pt-online-schema-change` tool?

Tags:

sql

mysql

percona

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

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?

like image 511
einnocent Avatar asked Oct 02 '14 18:10

einnocent


People also ask

How do you change PT online schema?

pt-online-schema-change works by creating an empty copy of the table to alter, modifying it as desired, and then copying rows from the original table into the new table. When the copy is complete, it moves away the original table and replaces it with the new one. By default, it also drops the original table.

What is online schema change in SQL Server?

online-schema-change alters a table's structure without blocking reads or writes.. GeoPITS brings you the comprehensive details of Online schema change's support in different versions & editions of SQL Server.


2 Answers

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

like image 91
wild_wire Avatar answered Oct 20 '22 05:10

wild_wire


According to the documentation for MySQL CREATE INDEX:

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

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

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

Resulting in the Percona schema modification statement:

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

like image 20
einnocent Avatar answered Oct 20 '22 05:10

einnocent