Re: Query Taking 2.5hrs on 5.6.20 version
If you want humans to read the query, why not format it for human readability?
First impressions ...
(i) the query is invalid because
select a,b,c,d,e,f,g, ..., <aggregates> ... group by a,b
can return arbitrary values for non-grouped and non-aggregated columns c,d,e,f,g.
(ii) each Left Join requires a table scan of the left-sided table, so it might be rewarding to revisit the data model to find a way to turn the Left Joins into Inner Joins, which optimise.
That's significant because, as it stands, the query requires reading 6809*2*41182*2*41182*10476*10308*5966*112 = 27.5 octillion (10^27) data rows, even though the biggest table has just 42K rows!
(iii) the complexity of the Select list and the Join list cries out for a data cube
Are these InnoDB tables? What's innodb_buffer_pool_size? How much RAM is there?