Hi,

 

I have a query at the moment like this:

 

SELECT SQL_NO_CACHE STRAIGHT_JOIN t1.col1, t1.col2, t2.col1, ...
MAX(t1.col6)...

(

            SELECT Count(DISTINCT col1)

            FROM table3 t3

            WHERE t3.col1 = t1.col1 AND t3.col2 = t1.col2 AND t3.col1 IN
(139903,140244,140583,140924,141265,141601,141942)

) AS uniquecount

FROM table1 t1 

INNER JOIN table2 t2 ON t1.col6 = t2.id

WHERE t2.id IN (139903,140244,140583,140924,141265,141601,141942)

GROUP BY t1.col1, t1.col2, t1.col3

ORDER BY NULL

 

Basically, you can tell that theres a main table with information that's
aggregated, and then another table with matching rows to aggregate too - per
row for the first table.

 

This appears very slow. I've tried running the queries separately and they
appear to be performing better on their own (as somewhat expected).

 

Does anyone have any ideas on how to optimize the above query? I think I
will just go with the latter dual query approach as it is more gentle on the
database server too.

 

Cheers,

Andrew

Reply via email to