Add a index which will help SELECT COUNT(*) FROM "works" WHERE "works"."published" = ? AND "works"."city_id" = ? run faster.