I have this users table with:
id : int (255)
name: char (100)
last_comment_target: int(100)
last_comment_date: datetime
This table has around 1.3mil rows.
PKEY and BTREE is on id, last_comment_target, and last_comment_date.
And, I am trying to perform a range query:
SELECT * FROM users
WHERE id IN (1,2,3,5,...[around 5000 ids])
AND last_comment_target > 0
ORDER BY last_comment_dt DESC LIMIT 0,20;
Sometimes the query can take as long as 3 seconds. I wonder if there are better ways to optimize this query. Or, if this query can be rewritten.
Thank you so much for your help.