I am reading the book High Performance MySQL and messing around with a new database testing somethings.
I am not sure if I am doing something wrong though..
I have a table called table_users
Structure:
ID(Integer)
FullName(Char)
UserName(Char)
Password(Char)
SecurityID(TinyINT)
LocationID(TinyINT)
Active(TinyINT)
My indexes are as follows:
PRIMARY : ID
FullName : UNIQUE : FullName
FK_table_users_LocationID (foreign key reference) : INDEX : LocationID
FK_table_users_SecurityID (foreign key reference) : INDEX : SecurityID
Active : INDEX : Active
All are BTREE
While reading the book, I am trying to use the following mysql statement to view the extras involved with a SELECT statement
EXPLAIN
SELECT * FROM table_users WHERE
FullName = 'Jeff';
No matter what the WHERE statement points to with this call, the extra result is either nothing or Using where. If I SELECT ID … WHERE FullName = ‘Jeff’ it returns Using where, Using Index. But not whenever I do SELECT FullName …. WHERE FullName = ‘Jeff’..
I am not familiar at all with indexes and trying to wrap my head around them bit having a bit of confusion with this. Shouldn’t they return Using Index if I am referencing an indexed column?
Thanks.
Using index doesn’t mean what it seems to mean. Have a look at covering indexes. If it says “using index” it means that mysql could return the data for your query without reading the actual rows. SELECT * – is only going to be able to use a covering index if even column of the table is in the index. Usually this is not the case.
I seem to remember a Chapters in High Performance Mysql that talks about covering indexes and how to read EXPLAIN results.