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 3B54BD1C4C8 for ; Wed, 13 Aug 2003 14:50:13 +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 25597-09 for ; Wed, 13 Aug 2003 11:48:41 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 01E6FD1B524 for ; Wed, 13 Aug 2003 11:50:01 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Wed Aug 13 16:50:04 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id QAA25601; Wed, 13 Aug 2003 16:50:03 +0200 (METDST) Message-ID: <3F3A501A.FDF96A90@rodos.fzk.de> Date: Wed, 13 Aug 2003 16:50:03 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org, wahab@mimos.my Subject: Re: How to speeed up the query performance Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200308/135 X-Sequence-Number: 14751 > > 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