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; -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance