Bug #120209 Feature Request: EXPLAIN ALTER TABLE
Submitted: 3 Apr 9:39 Modified: 11 Apr 11:53
Reporter: George Ma (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S4 (Feature request)
Version:8.4.7 OS:Any
Assigned to: CPU Architecture:Any

[3 Apr 9:39] George Ma
Description:
## Feature: EXPLAIN ALTER TABLE

### Problem Statement

MySQL's `ALTER TABLE` supports three execution algorithms — **INSTANT**,
**INPLACE**, and **COPY** — with fundamentally different performance and
availability characteristics:

| Algorithm | Mechanism | Typical Duration | Write Concurrency |
|-----------|-----------|-----------------|-------------------|
| INSTANT   | Metadata-only, no rebuild | Milliseconds | Unblocked |
| INPLACE   | Online DDL, no full copy | Seconds to minutes | Unblocked (or reads-only) |
| COPY      | Full table rebuild via temp copy | Minutes to hours | **Blocked** |

The algorithm actually chosen depends on a complex combination of factors:
storage engine capabilities, operation type, table schema, row format,
foreign key presence, session variables (`old_alter_table`), and any
explicit `ALGORITHM=` / `LOCK=` hints. **None of this is observable
without actually executing the statement.**

This creates a real operational problem:

1. **No preview without execution.** A DBA who wants to know whether
   `ALTER TABLE orders MODIFY COLUMN amount DECIMAL(20,4)` will block
   writes for 30 minutes or complete instantly must either run it on
   production (risky), test it on a replica (time-consuming), or guess
   from documentation (unreliable — behavior varies by schema, engine
   version, and configuration).

2. **Documentation cannot cover all cases.** The manual describes which
   operations *generally* support online DDL, but actual algorithm
   selection also depends on runtime state: whether `old_alter_table` is
   set, whether the table is temporary, whether `foreign_key_checks` is
   ON, whether combined clauses interact, and what the engine returns
   for the specific operation set.

3. **`ALGORITHM=` is not a dry-run tool.** Specifying `ALGORITHM=INPLACE`
   either forces the algorithm (causing an error if unsupported) or
   confirms the user's choice — it does not reveal what would have been
   chosen automatically.

4. **No equivalent to `EXPLAIN` for DDL.** MySQL users have long had
   `EXPLAIN SELECT` to understand query execution before running it. DDL
   has no such capability, despite DDL often carrying far more severe
   performance consequences than a slow query.

---

### Proposed Solution

Add `EXPLAIN ALTER TABLE` (also accepted as `DESC ALTER TABLE` /
`DESCRIBE ALTER TABLE`), which returns a single-row result set describing
the algorithm, lock level, and reason — without executing the DDL:

```sql

mysql> EXPLAIN ALTER TABLE orders ADD INDEX idx_status(status);
+--------+-----------+------+------------------------------------+
| Table  | Algorithm | Lock | Note                               |
+--------+-----------+------+------------------------------------+
| orders | INPLACE   | NONE | Online DDL, concurrent read/write  |
+--------+-----------+------+------------------------------------+

mysql> EXPLAIN ALTER TABLE orders MODIFY COLUMN amount DECIMAL(20,4);
+--------+-----------+--------+----------------------------------------------+
| Table  | Algorithm | Lock   | Note                                         |
+--------+-----------+--------+----------------------------------------------+
| orders | COPY      | SHARED | Table rebuild required, concurrent read only |
+--------+-----------+--------+----------------------------------------------+

```

How to repeat:
None
[11 Apr 11:53] MySQL Verification Team
Thank you very much for your patch contribution, we appreciate it!

In order for us to continue the process of reviewing your contribution to MySQL, please send us a signed copy of the Oracle Contributor Agreement (OCA) as outlined in https://oca.opensource.oracle.com

Signing an OCA needs to be done only once and it's valid for all other Oracle governed Open Source projects as well.

Getting a signed/approved OCA on file will help us facilitate your contribution - this one, and others in the future.  

Please let me know, if you have any questions.

Thank you for your interest in MySQL.