X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 890F4D1C9DC for ; Thu, 14 Aug 2003 02:52:28 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 30491-03 for ; Wed, 13 Aug 2003 23:50:50 -0300 (ADT) Received: from filter.mimos.my (filter.mimos.my [192.228.137.70]) by svr1.postgresql.org (Postfix) with ESMTP id AD138D1C4E7 for ; Wed, 13 Aug 2003 23:51:40 -0300 (ADT) Received: from ew.mimos.my (localhost.localdomain [127.0.0.1]) by filter.mimos.my (8.11.6/8.11.6) with ESMTP id h7E2GMr06139; Thu, 14 Aug 2003 10:16:22 +0800 Received: (from root@localhost) by ew.mimos.my (8.12.3/8.12.3) id h7E2phnj092970; Thu, 14 Aug 2003 10:51:43 +0800 (MYT) (envelope-from wahab@mimos.my) Received: from mimos.my (sol-wel197.nat.mimos.my [10.1.23.197]) by ew.mimos.my (8.12.3/8.11.6) with ESMTP id h7E2pdtv092378; Thu, 14 Aug 2003 10:51:41 +0800 (MYT) (envelope-from wahab@mimos.my) Message-ID: <3F3AF940.9000002@mimos.my> Date: Thu, 14 Aug 2003 10:51:44 +0800 From: Abdul Wahab Dahalan User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Christoph Haller Cc: pgsql-sql@postgresql.org Subject: Re: How to speeed up the query performance References: <3F3A501A.FDF96A90@rodos.fzk.de> X-scanner: scanned by Inflex 1.0.10 - (http://pldaniels.com/inflex/) Content-Type: multipart/alternative; boundary="------------040005000106080806050100" X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/163 X-Sequence-Number: 14779 --------------040005000106080806050100 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Hai Chris! Thanks for the solution but seem it doesnt work. (0 rows) returned when I used NOT EXITS but (4 rows) returned when NOT IN is used................... FYI I used 7.2 Christoph Haller wrote: >>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 > > > > > --------------040005000106080806050100 Content-Type: text/html; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit Hai Chris!
Thanks for the solution but seem it doesnt work.
(0 rows) returned when I used NOT EXITS but (4 rows) returned
when NOT IN is used...................

FYI I used 7.2

Christoph Haller wrote:
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



  

--------------040005000106080806050100--