Re: How to speeed up the query performance

From: Abdul Wahab Dahalan <wahab(at)mimos(dot)my>
To: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to speeed up the query performance
Date: 2003-08-14 02:51:44
Message-ID: 3F3AF940.9000002@mimos.my
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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
>
>
>
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-08-14 03:12:24 Re: How to speeed up the query performance
Previous Message Rod Taylor 2003-08-13 19:54:19 Re: Why table has drop, but the foreign key still there?