Your queries are the same from the perspective of the compiler. Either index will work. The order of the clauses in the where
statement is immaterial to qualifying a query for an index.
However, if you have inequalities or only one clause, then the ordering in the index makes a difference.
So, the index index(user_id, following_user_id)
would be useful for these situations:
- any comparison directly on user_id (except <>)
- user_id = XXX and folowing_user_id = YYY
- user_id = XXX and folowing_user_id /IN values
It would not be used for:
- folowing_user_id < YYY