Advanced Database Indexing & Optimization
In Tutorial 4, we cleaned the database. Now, we are going to tune the engine.
Warning: This is an advanced tutorial. It involves running SQL commands. Backup your database first.
What is an Index?
Imagine a library without an index system. To find a book, you'd have to walk through every shelf. That's a "table scan." An index allows the database to go directly to the row it needs.
Step 1: Adding Indexes to wp_options
The wp_options table is queried on every page load. By default, WordPress indexes the autoload column, but sometimes queries search by option_name.
If you have a large site, adding an index to autoload (if missing) can help.
Run this in phpMyAdmin:
[object Object], wp_options ,[object Object], INDEX autoload (autoload);
Step 2: Cleaning up wp_postmeta
This table grows exponentially. Every plugin adds metadata here.
-
Find Orphaned Metadata:
[object Object], ,[object Object], ,[object Object], wp_postmeta pm ,[object Object], ,[object Object], wp_posts wp ,[object Object], wp.ID ,[object Object], pm.post_id ,[object Object], wp.ID ,[object Object], ,[object Object],;This finds meta rows attached to posts that no longer exist.
-
Delete Them:
[object Object], pm ,[object Object], wp_postmeta pm ,[object Object], ,[object Object], wp_posts wp ,[object Object], wp.ID ,[object Object], pm.post_id ,[object Object], wp.ID ,[object Object], ,[object Object],;
Step 3: Converting Tables to InnoDB
Older WordPress installations might still use the MyISAM storage engine. InnoDB is much faster and supports row-level locking.
- Open phpMyAdmin.
- Check the Type column for your tables.
- If you see MyISAM, click the table name.
- Go to Operations.
- Change Storage Engine to InnoDB.
- Click Go.
Note: Most modern hosts do this automatically.
Conclusion
These advanced tweaks ensure your database engine runs smoothly. While plugins can clean the surface, these structural changes optimize the core.
Finally, we will look at Monitoring Tools, so you can track your speed over time.