/ Published in: MySQL
                    
                                        
This script shows the top 10 worst indexes (in terms of selectivity %) on the whole MySQL server instance. Selectivity is the percentage of distinct values in an indexed field compared to the number of records in the table.
Note that this query can take some time to complete on servers with lots of databases or lots of tables.
Jay Pipes (http://jpipes.com/)
                Note that this query can take some time to complete on servers with lots of databases or lots of tables.
Jay Pipes (http://jpipes.com/)
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/*
SQL script to grab the worst performing indexes
in the whole server
*/
t.TABLE_SCHEMA AS `db`
, s.SEQ_IN_INDEX `seq in index`
FROM INFORMATION_SCHEMA.STATISTICS s
ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
AND s.TABLE_NAME = t.TABLE_NAME
TABLE_SCHEMA
, TABLE_NAME
, INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
) AS s2
ON s.TABLE_SCHEMA = s2.TABLE_SCHEMA
AND s.TABLE_NAME = s2.TABLE_NAME
AND s.INDEX_NAME = s2.INDEX_NAME
ORDER BY `sel %`, s.TABLE_SCHEMA, s.TABLE_NAME /* Switch to `sel %` DESC for best non-unique indexes */
URL: http://forge.mysql.com/tools/tool.php?id=85
Comments
 Subscribe to comments
                    Subscribe to comments
                
                