Forum Moderators: open
Currently it takes an average of 280 seconds to generate all the sums.
This is the query:
SELECT c.CusName , t.thickness , t.product , (SELECT SUM(dollars) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) AND s.product=t.product AND s.thickness=t.thickness) AS s2007 , (SELECT SUM(dollars) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) AND s.thickness=t.thickness ) AS sTotal_2007, (SELECT SUM(dollars) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) ) AS sCTotal_2007 , (SELECT SUM(SQFT) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) AND s.product=t.product AND s.thickness=t.thickness) AS f2007 , (SELECT SUM(SQFT) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) AND s.thickness=t.thickness ) AS fTotal_2007, (SELECT SUM(SQFT) FROM sp_a as s USE INDEX(cust_id) WHERE s.cust_id=t.cust_id AND s.year=2007 AND month IN (1,2,3,4) ) AS fCTotal_2007 FROM customer_a as c USE INDEX(CusNum) RIGHT JOIN sp_a AS t USE INDEX(year) ON c.CusNum=t.cust_id WHERE year =2007 AND month IN (1,2,3,4) GROUP BY t.cust_id , t.thickness , t.product
Is there some other way of generating these sums? I've tried separating out the queries but it seems to slow down the page even more.
Any ideas?
With those subqueries I'm not sure the indexes are helping you:
[bugs.mysql.com...]
There are some tips in that bug discussion regarding using SQL_BIG_RESULT, etc that you might try.
But I'm just guessing here.