Need to speed up MySQL Subquery -


hey have mysql query uses nested subquery.

i have tried many ways speed takes 2 seconds run , slowing down webpage.

how can speed query? have tried using views , query caching performance benefits nominal.

select w.wid,                max(wb.blockprice) highestprice,                min(wb.blockprice) lowestprice,                max(bi.impressions) highestimpressions,                min(bi.impressions) lowestimpressions                         website w                         join website_block wb on wb.wid = w.wid                     join website_block_impressions wbi on wbi.wbid = wb.wbid , wbi.statdate > date_sub(now(),interval 1 day)                 join (                 select round((sum(impressions) / count(impdate)) * 30) impressions, wid widimpressions                   (select count(wbi.wbiid) impressions,                               cast(wbi.statdate date) impdate,                               wbi.wbid,                               wb.wid                           website_block_impressions wbi                           join website_block wb on wb.wbid = wbi.wbid                           wb.blockenabled = 1                            , wb.archived = 0                           , `wbi`.statdate > date_add(now(), interval -wb.blockduration day)                           group cast(wbi.statdate date), wbi.wbid) impressions                   group wbid) bi                         w.archived = 0                         , w.approved = 1                         , bi.widimpressions = w.wid                         , bi.impressions between 0 , 73000                         group w.wid             limit 0,10 

any appreciated.

you'll want add indexes on criteria. example, add index containing fields w.archived , w.approved. without indices that, mysql have scan every single row first, instead of knowing rows should working with.

but scrum meister mentioned, we'll need see explain output , table definitions have better idea of bottlenecks , how address them.

if can't there plenty of resources on net understand how create optimal indexes increased query speed. slideshow gives basic overview of start: http://www.slideshare.net/manikandakumar/mysql-query-and-index-tuning


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -