content_image/670254.jpg content_image/670257.jpg
2. Enable the stage event consumer tables, which include events_stages_current , events_stages_history , and events_stages_history_long . 

mysql> UPDATE performance_schema.setup_consumers SET ENABLED = ’YES’ WHERE NAME LIKE ’%stages%’; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 

3. Run an ALTER TABLE  operation. In this example, a middle_name  column is added to the employees table of the employees sample database. 

mysql> ALTER TABLE employees.employees ADD COLUMN middle_name varchar(14) AFTER first_name; Query OK, 0 rows affected (9.27 sec) Records: 0 Duplicates: 0 Warnings: 0 

4. 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. The WORK_ESTIMATED  column provides an estimate of the remaining work. 

mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED FROM performance_schema.events_stages_current; 

<img src='content_image/670254.jpg'>

The events_stages_current  table returns an empty set if the ALTER TABLE  operation has completed. In this case, you can check the events_stages_history  table to view event data for the completed operation. For example: 

mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED FROM performance_schema.events_stages_history; 

<img src='content_image/670257.jpg'>

As shown above, the WORK_ESTIMATED  value was revised during ALTER TABLE  processing. The estimated work after completion of the initial stage is 1213. When ALTER TABLE  processing completed, WORK_ESTIMATED  was set to the actual value, which is 1981. 

## 15.16.2 Monitoring InnoDB Mutex Waits Using Performance Schema 

A mutex is a synchronization mechanism used in the code to enforce that only one thread at a given time can have access to a common resource. When two or more threads executing in the server need to access the same resource, the threads compete against each other. The first thread to obtain a lock on the mutex causes the other threads to wait until the lock is released. 

For InnoDB  mutexes that are instrumented, mutex waits can be monitored using Performance Schema. Wait event data collected in Performance Schema tables can help identify mutexes with the most waits or the greatest total wait time, for example. 

