Adds an index to a specified table.
Parameters
$tablestringrequired- Database table name.
$indexstringrequired- Database table index column.
Source
function add_clean_index( $table, $index ) {
global $wpdb;
drop_index( $table, $index );
$wpdb->query( "ALTER TABLE `$table` ADD INDEX ( `$index` )" );
return true;
}
Changelog
| Version | Description |
|---|---|
| 1.0.1 | Introduced. |
Sometimes after a table has been created in a database, we find that it is advantageous to add an index to that table to speed up queries involving this table.
Adding indexes to existing tables can significantly enhance query performance, especially in large databases. The add_clean_index function simplifies this process by automatically removing an existing index before creating a new one, preventing potential conflicts and duplication.
Recommendations: