Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to see the progress of an ALTER TABLE statement in MySQL?

Tags:

mysql

For example, I issued an ALTER TABLE statement to create an index on a MEDIUMTEXT field in an InnoDB table that has 134k rows where the size of the index was 255 bytes and the average size of the data in the field is 30k. This command has been running for the last 15 minutes or so (and is the only thing running on the database). Is there any way for me to determine if it is going to finish in closer to 5 minutes, 5 hours, or 5 days?

like image 586
John Avatar asked Sep 04 '08 09:09

John


People also ask

How do I check the progress of my ALTER TABLE?

Check the progress of the ALTER TABLE operation by querying the Performance Schema events_stages_current table. The stage event shown differs depending on which ALTER TABLE phase is currently in progress. The WORK_COMPLETED column shows the work completed.

How can I tell when a table was last analyzed in MySQL?

If you have the general log enabled, simply do a grep -i "analyze table" against the general log file and locate the timestamp just about the command.

What happens to view when table is altered?

No, it shouldn't prevent the table from being altered. Though, if you drop the underlying table a view depends on, or alter/remove the columns from the table the view uses, the view can become invalid.

How do I view table records in MySQL?

The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.


2 Answers

I was able to perform these 2 queries and figure out how many rows remain to be moved.

select count(*) from `myoriginalrable`; select count(*) from `#sql-1e8_11ae5`; 

this was WAY more helpful than comparing the file size on disk, because changing from myisam to innodb etc changes the row size.

like image 149
Jay Binks Avatar answered Sep 20 '22 23:09

Jay Binks


In the case of InnoDB tables, one can use SHOW ENGINE INNODB STATUS to find the transaction doing the ALTER TABLE and check how many row locks the TX holds. This is the number of processed rows. Explained in detail here:

http://gabrielcain.com/blog/2009/08/05/mysql-alter-table-and-how-to-observe-progress/

Also MariaDB 5.3 and later has the feature to report progress for some operations (including ALTER TABLE). See:

http://kb.askmonty.org/en/progress-reporting/

like image 25
Axel Avatar answered Sep 16 '22 23:09

Axel