|
| 1 | +# Thread states for DROP TABLE operations |
| 2 | + |
| 3 | +Percona Server for MySQL 9.7 adds two performance schema stages for `DROP TABLE` operations. The stages mark the start and the end of a table drop. Use the stages to check whether a session actively runs a table drop. The stages help diagnose long-running or blocked `DROP TABLE` statements. |
| 4 | + |
| 5 | +Check the status of [PS-10452](https://github.com/percona/percona-server/pull/6065) before you publish this page. The pull request is open and targets the `9.7` branch. |
| 6 | + |
| 7 | +## Stages |
| 8 | + |
| 9 | +The following table lists the two stages: |
| 10 | + |
| 11 | +| Stage | Description | |
| 12 | +|---|---| |
| 13 | +| `stage/sql/dropping table` | The thread starts the drop operation. Percona Server for MySQL sets this stage at the start of `drop_base_table()` for base tables and at the start of `drop_temporary_table()` for temporary tables. | |
| 14 | +| `stage/sql/after drop` | The thread completes the drop routine and returns. | |
| 15 | + |
| 16 | +Percona Server for MySQL implements the stages as standard `PSI_stage_info` entries: `stage_dropping_table` and `stage_after_drop`. The server sets the stages with `THD_STAGE_INFO()` calls in `sql/sql_table.cc` and `sql/sql_base.cc`. This pattern matches the existing `creating table` and `After create` stages for `CREATE TABLE`. |
| 17 | + |
| 18 | +A `DROP TABLE` statement completes fast. The two stages stay visible for a short time only. Query the stage history in Performance Schema to capture the stages. Do not rely only on `SHOW PROCESSLIST`. |
| 19 | + |
| 20 | +## Stage history example |
| 21 | + |
| 22 | +Truncate the stage history, run a `DROP TABLE` statement, and query the recorded stage events: |
| 23 | + |
| 24 | +```sql |
| 25 | +TRUNCATE TABLE performance_schema.events_stages_history_long; |
| 26 | + |
| 27 | +DROP TABLE test.t1; |
| 28 | + |
| 29 | +SELECT EVENT_NAME |
| 30 | +FROM performance_schema.events_stages_history_long |
| 31 | +ORDER BY EVENT_ID; |
| 32 | +``` |
| 33 | + |
| 34 | +The following output shows the relevant stages: |
| 35 | + |
| 36 | +``` |
| 37 | +EVENT_NAME |
| 38 | +stage/sql/starting |
| 39 | +stage/sql/checking permissions |
| 40 | +stage/sql/dropping table |
| 41 | +stage/sql/after drop |
| 42 | +stage/sql/waiting for handler commit |
| 43 | +stage/sql/query end |
| 44 | +stage/sql/closing tables |
| 45 | +stage/sql/freeing items |
| 46 | +stage/sql/cleaning up |
| 47 | +``` |
| 48 | + |
| 49 | +The `INFORMATION_SCHEMA.PROFILING` table shows the same stages without the `stage/sql/` prefix: `dropping table` and `after drop`. Percona deprecated `INFORMATION_SCHEMA.PROFILING`. Use Performance Schema instead. |
| 50 | + |
| 51 | +## Notes |
| 52 | + |
| 53 | +The following notes apply to the two stages: |
| 54 | + |
| 55 | +- The stages apply to base tables and temporary tables |
| 56 | + |
| 57 | +- The stage names use lowercase, plain English text, consistent with existing stage names such as `creating table` and `After create` |
| 58 | + |
| 59 | +- If `performance_schema.threads` or `SHOW PROCESSLIST` does not show the stages, the drop operation likely completed before the sample. Query `events_stages_history_long` for a reliable trace |
0 commit comments