Re: avoiding seq scan without duplicating

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrus" <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: avoiding seq scan without duplicating
Date: 2008-11-07 13:26:10
Message-ID: 28460.1226064370@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Andrus" <kobruleht2(at)hot(dot)ee> writes:
> Simple query is slow, performs seq scan while index exists:
> explain select count(*)::integer as cnt
> from firma2.dok
> where dokumnr in (888817,2) and
> dokumnr not in (select dokumnr FROM firma2.bilkaib WHERE
> alusdok='LF' -- and dokumnr in (888817,2)
> )

> Index is used if join condition is duplicated in subquery:

> explain select count(*)::integer as cnt
> from firma2.dok
> where dokumnr in (888817,2) and
> dokumnr not in (select dokumnr FROM firma2.bilkaib WHERE
> alusdok='LF' and dokumnr in (888817,2)
> )

The proposed transformation is not correct because of the odd behavior
of NOT IN with respect to nulls.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2008-11-07 13:31:42 Re: UPDATE tuples with a sub-select
Previous Message Andrus 2008-11-07 12:49:01 avoiding seq scan without duplicating