Re: Optimizing IN queries

From: "Isak Hansen" <isak(dot)hansen(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Optimizing IN queries
Date: 2008-11-10 13:09:13
Message-ID: 6b9e1eb20811100509u500daddfibe7b75845b0b5f49@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Nov 10, 2008 at 12:35 PM, Andrus <kobruleht2(at)hot(dot)ee> wrote:

> explain analyze select count(*)::INTEGER as cnt
> from dok
> WHERE dokumnr IN
> (869906,869907,869910,869911,869914,869915,869916,869917,869918,869921 )
> and
> dokumnr NOT IN (SELECT dokumnr FROM bilkaib WHERE
> alusdok='LY')
>

Looks to me like most of the time is spent doing "not in (select a ton
of rows from bilkaib)".

Try something like "not exists (select null from bilkaib b where
b.dokumnr = dok.dokumnr and alusdok = 'LY')".

HTH, Isak

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2008-11-10 13:53:20 Re: Optimizing IN queries
Previous Message Thomas Kellerer 2008-11-10 12:58:08 Re: Importing text file into a TEXT field