Database Table Optimization
ZiziCache can optimize database tables using MySQL OPTIMIZE TABLE. Optimization is triggered manually from the Database tools or via the REST API; it is not executed automatically as part of the scheduled cleanup job.
Types of Table Optimization
The plugin provides two execution paths with different scopes:
- Standard optimization (admin quick action
/optimize-db-tables): optimizes only non-InnoDB tables that show fragmentation (data_free > 0). - Safe batch optimization (
/optimize-db-tables-batch): processes tables one by one and includes InnoDB tables only when fragmentation is detected (data_free > 0).
Safety Measures
Safety controls depend on the execution path:
- Fragmentation check: tables are selected using
data_freefrominformation_schema. - Size limit (batch only): tables larger than 500 MB are skipped.
- Per-table processing (batch only): tables are optimized sequentially with a short pause between runs.
- Transaction wrappers (batch only): non-InnoDB tables are wrapped with
START TRANSACTION/COMMIT/ROLLBACK.
Optimization Statistics
Detailed statistics are returned only by the batch endpoint:
- Total optimized, skipped, and error counts
- Saved bytes per table
- Per-table execution time and status
- Skip reasons or error messages
The standard optimization action does not return per-table statistics.
Automatic Optimization
The db_optimize_tables flag enables table optimization when it is explicitly requested (manual cleanup or REST API). The scheduled cleanup job does not run table optimization automatically.