Re: NOT IN doesn't use index? (fwd) - Mailing list pgsql-performance

From Joe Conway
Subject Re: NOT IN doesn't use index? (fwd)
Date
Msg-id 3EB41900.5010407@joeconway.com
Whole thread Raw
In response to Re: NOT IN doesn't use index? (fwd)  (Becky Neville <rebecca.neville@yale.edu>)
Responses Re: NOT IN doesn't use index? (fwd)  (Becky Neville <rebecca.neville@yale.edu>)
List pgsql-performance
Becky Neville wrote:
> Well I think you answered my question already, but just in case
> here are the explain results again and the query follows (I warned, it is
> long.)  And I did run VACUUM ANALYZE beforehand.

[snipped ugly query with three NOT IN clauses]

Hmmm, no surprise that's slow. How are those three lists of constants
generated? One idea is to recast this as a left join with a FROM clause
subselect, e.g.

select
  uabopen_srat_code
from
  uabopen u left join
  (select '1F' as uabopen_srat_code union all
          '1FD' union all
          '3A' ...) as ss
  on u.uabopen_srat_code = ss.uabopen_srat_code
where ss.uabopen_srat_code is null;

But I'm not sure that will be much quicker. If the list of
uabopen_srat_code you're filtering on comes from one of the other
tables, you might be able to do better -- back to the question above,
how is that list generated? What do the other table look like?

Joe


pgsql-performance by date:

Previous
From: Becky Neville
Date:
Subject: Re: NOT IN doesn't use index? (fwd)
Next
From: Becky Neville
Date:
Subject: Re: NOT IN doesn't use index? (fwd)