I have a query in my database as such:
SELECT * FROM expenses WHERE user_id = ? AND dated_on = ?
I added an index to the user_id and dated_on column table. When I check indexes using SHOW INDEXES FROM expenses , there are two lines: one with seq_in_index value 1, the other with seq_in_index value 2.
My question is: if I then send a request that uses only one of the two WHERE clauses, for example:
SELECT * FROM expenses WHERE user_id = ?
Is there any use for creating another index that only indexes the user_id column, or will the user_id / dated_on index also known above be used?
Finally, how about using a query:
SELECT * FROM expenses WHERE dated_on = ?
How does the value of seq_in_index 2 affect the use and performance of the index in this situation?
sql mysql indexing
Olly
source share