I wrote this query for seeing if the size of the indexes in certain tables were larger than the actual amount of data in the table, using MySQL 5.6 and InnoDB as the engine.
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) 'Size in MB', IF(index_length > data_length, 1, 0) as poorIndexing FROM information_schema.TABLES
The results are that some of the tables have much larger index_lengths than their actual data table. I was under the impression that this meant that MySQL would skip over the indexes and simply do a full table scan because there is less data to parse in the entire table than the index.
However, is this true if an individual index is smaller than the aggregate? I.e. if I'm doing something like
"SELECT * FROM user WHERE id = 244", and the id is indexed, but so is the address, phone, username, email, etc. does InnoDB just use the id or does MySQL see the size of the entire operation and simply skip over it. Or is it only a problem if the query is :
SELECT username FROM users WHERE username = 'johnrambothe14th';
And the total amount of indexes for username is greater than the total amount of data?