pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Haller <ch@rodos.fzk.de>
To: pgsql-sql@postgresql.org
To: wahab@mimos.my
Subject: Re: How to speeed up the query performance
Date: Wed, 13 Aug 2003 16:50:03 +0200
Message-ID: <3F3A501A.FDF96A90@rodos.fzk.de> (raw)

>
> How do I speed up the quey performance if I've a query like this :
> Does 'not in' command will affected the performance?.
Yes, it's well known to be slow in 7.3 and lower, should be fixed in 7.4
AFAIK.
>
> select
>
ts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumber

> from       transportsetup ts
> where     ts.bizid = 'B126'
> and         ts.deletestatus = 0
> and         ts.transportid not in (    select t.transportid
>                                                   from transportsetup
t,servicedetail s,logisticservice l
>                                                   where
t.bizid=l.bizid
>                                                       and
l.serviceid=s.serviceid
>                                                       and
t.transportid=s.transportid
>                                                       and t.bizid =
'B126'
>                                                       and
l.status='Pending'
>                                                   or t.bizid=l.bizid
>                                                       and
l.serviceid=s.serviceid
>                                                       and
t.transportid=s.transportid
>                                                       and t.bizid =
'B126' and l.status='Reserved' )
> order by ts.transporttype;
>
As recently mentioned by Stephan Szabo on '[SQL] How to optimize this
query ?'
NOT EXISTS performs much better.

Try:
select
ts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumber

from    transportsetup ts
where   ts.bizid = 'B126'
and     ts.deletestatus = 0
and     NOT EXISTS (    select t.transportid
        from transportsetup t,servicedetail s,logisticservice l
        where ts.transportid = t.transportid
            and t.bizid=l.bizid
            and l.serviceid=s.serviceid
            and t.transportid=s.transportid
            and t.bizid = 'B126'
            and l.status='Pending'
        or t.bizid=l.bizid
            and l.serviceid=s.serviceid
            and t.transportid=s.transportid
            and t.bizid = 'B126' and l.status='Reserved' )
order by ts.transporttype;

Regards, Christoph





view thread (7+ messages)  latest in thread

Message-ID: <3F3A501A.FDF96A90@rodos.fzk.de>
Permalink:  ../3F3A501A.FDF96A90@rodos.fzk.de/
Also on:    postgresql.org/message-id/3F3A501A.FDF96A90@rodos.fzk.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ch@rodos.fzk.de, wahab@mimos.my
  Subject: Re: How to speeed up the query performance
  In-Reply-To: <3F3A501A.FDF96A90@rodos.fzk.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox