I have the following Mysql query. It is a slow query and will take around 3 seconds to finish. message_id is the primary key. The problem of this is the high LIMIT offset LIMIT 85075, 25
.
SELECT * FROM `phorum_messages` WHERE 1 and `catergory` >=0 and parent_id=0 order by `message_id` desc LIMIT 85075, 25;
Based on this solution, I changed query to the following way. The problem is if I remove where parent_id=0
, the speed is much faster. But I really need where parent_id=0
EDIT: I already created index for parent_id and message_id.
Any suggestions? Thanks in advance.
SELECT t.*
FROM (
SELECT message_id
FROM phorum_messages where parent_id=0
ORDER BY message_id desc LIMIT 85075, 25
) q
JOIN phorum_messages t
ON t.message_id = q.message_id