What this thread does
Do first: run EXPLAIN FORMAT=TREE on the slow query, then use EXPLAIN ANALYZE FORMAT=TREE only where executing that query is acceptable.
Short answer
As of November 2026, this recipe targets MySQL 8.4.13, October 20, 2026 and ordinary InnoDB secondary indexes. Use the plan to identify excess row access before proposing an index. Enforce INPLACE and concurrent-DML support explicitly; unsupported requests should stop the rollout rather than fall back to a table copy.
Choose / don't choose
- EXPLAIN ANALYZE: choose for actual iterator timings/rows; don't run an expensive query on a busy primary merely to inspect estimates. It executes the query (EXPLAIN).
- Invisible index: choose to isolate optimizer adoption; don't expect it to avoid index-build cost or ongoing write maintenance (invisible indexes).
- Online secondary index: choose when the documented operation supports concurrent DML; don't assume FULLTEXT, SPATIAL or primary-key changes share that contract (operations).
Not for: transaction retry semantics; see mysql-error-1213-1205-lock-waits-rollback-retry.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
ALGORITHM | Require INPLACE; reject unsupported operation instead of default fallback | MySQL current 8.4 docs | DDL concurrency |
LOCK | Require NONE for concurrent reads/writes during supported operation; metadata locks still occur | MySQL current 8.4 docs | DDL concurrency |
INVISIBLE / VISIBLE | Build candidate INVISIBLE; use ALTER INDEX ... VISIBLE after comparison | MySQL current 8.4 docs | indexes |
optimizer_switch | SET_VAR(optimizer_switch = 'use_invisible_indexes=on'); default off | MySQL current 8.4 docs | indexes |
EXPLAIN ANALYZE FORMAT | TREE; JSON/TRADITIONAL are unsupported for ANALYZE | MySQL current 8.4 docs | EXPLAIN |
Order of operations
1. Capture a representative query shape and row distribution. Inspect scans, joins and filters. Compare estimated rows with actual rows at each iterator, accounting for loops; repeated inner scans amplify cost. Large estimate errors suggest checking statistics as well as index design. Large actual scans with few surviving rows motivate a candidate matching the predicates/order; estimates alone do not justify it. 2. Compare on representative data in a controlled environment. Establish disk headroom, replica lag and metadata-lock constraints before building. Illustrative schema names: ALTER TABLE orders ADD INDEX idx_customer_created (customer_id, created_at) INVISIBLE, ALGORITHM=INPLACE, LOCK=NONE; (operations). 3. Monitor build progress and metadata-lock waits. An old transaction can delay DDL and queued DDL can block later traffic. End the owning transaction through its application owner; do not drop lock/algorithm constraints as an automatic retry (concurrency). 4. Keep normal optimizer behavior off. In a separate diagnostic session enable use_invisible_indexes=on, compare actual rows, timings and write overhead, and restore the session setting before reuse. This makes the index eligible, not guaranteed to be chosen. Arunjith Aravindan's April 2, 2024 article describes SET_VAR for a single query. 5. Make the index VISIBLE only after representative comparisons; observe other query shapes too. If plans regress, return it to INVISIBLE while investigating. This reverses optimizer adoption without rebuilding, while write maintenance continues.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
ER_ALTER_OPERATION_NOT_SUPPORTED_REASON | The error catalog reports an unsupported operation with a reason and suggested alternative | Stop, inspect the documented restriction, and plan an explicit maintenance or different migration path | DDL failure conditions, error catalog |
Waiting for table metadata lock | Open transaction holds a conflicting metadata lock | Identify the holder and end it safely; bound the rollout window and avoid automatic stronger-lock retry | DDL concurrency example |
Missing
- Actual schema, selectivity, query plan, storage budget and traffic are unspecified; no concrete index is prescribed. LOCK=NONE does not mean zero locking or zero application impact.
Started from a post by @Oracle MySQL, packaged by the editor. Original post