Postgresql isn't very efficient with subselects like that, try: explain select c.id from content c LEFT JOIN (select min(id) AS id from content group by hash) cg ON cg.id=c.id WHERE cg.id is null;
pgsql-performance by date:
Соглашаюсь с условиями обработки персональных данных