Fixed query/Postgres query optimizer issue.