You can increase the performance by creating an index on comments(scrap_id)
:
create index comments_scrap_id on comments(scrap_id);
You could also try phrasing this as a join
and group by
:
SELECT co.*, count(com.scrap_id) as comment_count
FROM contents co left outer join
comments com
on co.org_scrap_id = com.scrap_id
GROUP BY co.id
---------^ or whatever the appropriate `id` is for this table
ORDER BY comment_count;
But the index is likely to give better performance.