I very often search the table posts
for values in the columns user
+status
and user
+time
.
SELECT * FROM `posts` WHERE `user`='xxx' and `status`='active'
SELECT * FROM `posts` WHERE `user`='xxx' and `time`>...
Thus I have set up two indices (user, status) and (user, time)
I'm aware, that writing processes are slowed down the more indices need to be updated. But I think in this case it is useful to have both indices, since reading operations outnumber writing operations by far.
Anyway, PHPMyAdmin gives a Warning saying "More than one index has been created for the column user". Can I just ignore this warning? I checked the Wordpress DB tables and saw that they have put a column at the second position, if it already had an index.
comment_approved_date_gmt = INDEX(comment_approved, comment_date_gmt)
comment_date_gmt = INDEX(comment_date_gmt)
Why don't they use only one two column index (INDEX(comment_date_gmt, comment_approved)), that would save INDEX(comment_date_gmt)? and why is it disadvantageous to have two indices starting with the same column-name?
Is there a general rule, which column should go first in my query? For example the one with the lowest number of different entries (e.G. status) and afterwards the one with a higher number of different values (e.g. user names)