Try replacing the forums_message__root_message_id(forums_messages.message_id) function call with a subquery that returns the equivalent result, or try putting a functional index on forums_message__root_message_id(forums_messages.message_id). Either method should eliminate the sequential scan.