Re: Slow SQL? - Mailing list pgsql-general

From Albe Laurenz
Subject Re: Slow SQL?
Date
Msg-id A737B7A37273E048B164557ADEF4A58B5386C301@ntex2010i.host.magwien.gv.at
Whole thread Raw
In response to Re: Slow SQL?  (hamann.w@t-online.de)
Responses Re: Slow SQL?  (Bjørn T Johansen <btj@havleik.no>)
List pgsql-general
hamann.w@t-online.de wrote:
Bjørn T Johansen wrote:
>> I am trying to move a small system from Oracle to PostgreSQL and I have come upon a sql that runs
>> really slow compared to on the Oracle database and I am not able to interpret why this is slow.

> I have experienced that some subqueries can be quite slow, and would suspect the NOT IN
> clause. I occasionally rewrite
> NOT IN (select key from unwanted_candidates)
> as
> IN (select key from possible_candidates except select key from unwanted_candidates)

I would try to rewrite these clauses to NOT EXISTS, for example

   a.avlsnr Not In (Select avlsnr From dyr_pause_mot)

could be

   NOT EXISTS (SELECT NULL FROM dyr_pause_mot WHERE avlsnr = a.avlsnr)

This can be executed as anti-join and is often more efficient.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: hamann.w@t-online.de
Date:
Subject: Re: Slow SQL?
Next
From: "dandl"
Date:
Subject: Question about antijoin