How to speeed up the query performance
How to speeed up the query performance
От:
Abdul Wahab Dahalan <wahab@mimos.my>
Дата:
How do I speed up the quey performance if I've a query like this :
Does 'not in' command will affected the performance?.
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
f rom 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;
Any help pretty much appreciated. Thanks
Re: How to speeed up the query performance
От:
Christoph Haller <ch@rodos.fzk.de>
Дата:
> > 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
Re: How to speeed up the query performance
От:
Jonathan Gardner <jgardner@jonathangardner.net>
Дата:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 12 August 2003 20:20, Abdul Wahab Dahalan 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. Severely. See the responses to the "How to optimize this query ?" thread. If you want more details, check the pgsql-performance archives. - -- Jonathan Gardner Live Free, Use Linux! -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE/OlBBWgwF3QvpWNwRAuzJAJ99iMmMbU/tiJhi077+8WCmAId76ACffL+5 biOZSLPbuhWZBL6MNlZE3V0= =Sg0n -----END PGP SIGNATURE-----
Re: How to speeed up the query performance
От:
Abdul Wahab Dahalan <wahab@mimos.my>
Дата:
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.selectts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumberfrom transportsetup ts where ts.bizid = 'B126' and ts.deletestatus = 0 and ts.transportid not in ( select t.transportid from transportsetupt,servicedetail s,logisticservice lwheret.bizid=l.bizidandl.serviceid=s.serviceidandt.transportid=s.transportidand t.bizid ='B126'andl.status='Pending'or t.bizid=l.bizid andl.serviceid=s.serviceidandt.transportid=s.transportidand 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
Re: How to speeed up the query performance
От:
Stephan Szabo <sszabo@megazone.bigpanda.com>
Дата:
On Thu, 14 Aug 2003, Abdul Wahab Dahalan wrote: > 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................... Maybe you need a set of parenthesis around the old conditions because of the or. > >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 Replace the above with: 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' ) Add: ) > >order by ts.transporttype;
Re: How to speeed up the query performance
От:
Abdul Wahab Dahalan <wahab@mimos.my>
Дата:
I cant find where to put the parenthesis as u said Stephan.
Here the query :
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;
Stephan Szabo wrote:On Thu, 14 Aug 2003, Abdul Wahab Dahalan wrote: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...................Maybe you need a set of parenthesis around the old conditions because of the or.Try: select ts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumber>from transportsetup tswhere ts.bizid = 'B126' and ts.deletestatus = 0 and NOT EXISTS ( select t.transportid from transportsetup t,servicedetail s,logisticservice l where ts.transportid = t.transportidand t.bizid=l.bizidReplace the above with: and (t.bizid=l.bizidand 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' )Add: )order by ts.transporttype;---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings
Re: How to speeed up the query performance
От:
Abdul Wahab Dahalan <wahab@mimos.my>
Дата:
Thanks Chris and Stephan
the query is working now.
Abdul Wahab Dahalan wrote:
I cant find where to put the parenthesis as u said Stephan.
Here the query :
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;
Stephan Szabo wrote:On Thu, 14 Aug 2003, Abdul Wahab Dahalan wrote: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...................Maybe you need a set of parenthesis around the old conditions because of the or.Try: select ts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumber>from transportsetup tswhere ts.bizid = 'B126' and ts.deletestatus = 0 and NOT EXISTS ( select t.transportid from transportsetup t,servicedetail s,logisticservice l where ts.transportid = t.transportidand t.bizid=l.bizidReplace the above with: and (t.bizid=l.bizidand 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' )Add: )order by ts.transporttype;---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings