"Josh Berkus" <josh@agliodbs.com> writes:
> UPDATE cases SET status = 99
> WHERE status = 1 AND NOT EXISTS(
> SELECT case_id FROM case_clients
> WHERE date_resolved IS NULL OR
> date_resolved > ((current_date - "interval"('1 year'))::DATE)
> and case_clients.case_id = cases.case_id);
It says here that OR binds at lower priority than AND. Did you really
mean
... WHERE (date_resolved IS NULL OR date_resolved > ((current_date - "interval"('1 year'))::DATE)) and
case_clients.case_id= cases.case_id);
Since IS NULL isn't indexable, the first version cannot be indexscanned
at all. The second version gives you a shot at using the
case_clients.case_id index.
regards, tom lane