optimize_table
Eliminate table fragmentation by rebuilding tables to reclaim unused space and boost query performance, with dry-run preview.
Instructions
[WRITE][risk=medium] OPTIMIZE TABLE (rebuild, reclaim data_free). Records prior stats.
No undo (a rebuild has no inverse); the prior size/fragmentation stats are captured for the audit trail. InnoDB maps this to ALTER TABLE ... FORCE (online DDL, brief locks) — schedule off-peak for hot tables. Pass dry_run=True to preview.
Args: table: Table name (optionally schema-qualified, e.g. shop.orders). dry_run: If True, preview without running. target: Target name from config; omit for the default.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | ||
| target | No | ||
| dry_run | No |