Re: Wierd query behaviour - Mailing list pgsql-sql

From Tom Lane
Subject Re: Wierd query behaviour
Date
Msg-id 12113.1019861021@sss.pgh.pa.us
Whole thread Raw
In response to Wierd query behaviour  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
"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


pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Function won't complete
Next
From: Tom Lane
Date:
Subject: Re: Function won't complete