I have a
message table in my application and one of the most commonly executed SQL queries on this table is the following one:
select * from message message0_ where message0_.sender_id=? or message0_.recipient_id=? order by message0_.send_date asc;
I am basically querying for the messages the current user has either received or sent.
The value of the parameter for
recipient_id is the current user ID.
I have created the following index:
CREATE INDEX ON message(recipient_id, sender_id);
I would like to know if the order of the fields matters for my use case bearing in mind the OR clause in my SQL query.
Can someone please help?