Unix Technical Forum

Performance issue with sub query

This is a discussion on Performance issue with sub query within the MySQL forums, part of the Database Server Software category; --> I have this query that runs horribly slow due to the sub queries I am using. select s. * ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:30 AM
raz230
 
Posts: n/a
Default Performance issue with sub query

I have this query that runs horribly slow due to the sub queries I am
using.

select
s. * ,
f. * ,
md.discount as man_disc ,
md.charge as man_upcharge ,
dd.discount as drug_disc ,
dd.charge as drug_upcharge ,
ep.discount as ep_discount_man ,
( select f.ship_fee / count( * ) from scripts where cforder_id =
s.cforder_id ) as ship_cost,
(select count( * ) from scripts where cforder_id = s.cforder_id) as
order_count
from scripts s
inner join client_fees f on s.customer_id = f.customer_id
left join client_man_discounts md on md.man = s.man and md.customer_id
= s.customer_id
left join client_drug_discounts dd on s.drugid = dd.drug_id
left join client_ep_discounts ep on ep.customer_id = s.customer_id and
s.man = ep.man
where s.customer_id = 7 and
s.status = 4 and
s.ship_date is not null and
s.ship_date != '0000-00-00'
and s.ship_date between '2007-10-01' and '2007-10-09';

I need the information provided by the sub queries and I was hoping to
avoid using three separate queries- that's why I used these sub's.

Each one adds ~ 5 seconds to the execution time of this query.

I know sub queries are inefficient, but I have used them before
without this much of a performance hit. My tables are InnoDB and I
have done my joins on the PK or FK of my tables.

Is there a better way to handle this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:17 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com