SELECT pid.date AS galleryDate, pid.time AS galleryTime, pid.name AS galleryName, pid.title AS galleryTitle, p.date AS pictureDate, p.time AS pictureTime, p.gallery AS pictureGallery, p.name AS pictureName, p.title AS pictureTitle, IFNULL(pid.countv,0) AS countViews, IFNULL(pid.countp,0) AS countPictures FROM ( SELECT g.date, g.time, g.name, g.title, MAX(p.id) AS maxid, SUM(countv) AS countv, COUNT(*) AS countp FROM pictures p LEFT JOIN galleries g ON p.idg = g.id GROUP BY p.idg ORDER BY g.id DESC ) pid LEFT JOIN pictures p ON pid.maxid = p.id ORDER BY p.id DESC LIMIT 10
Wykonuje mi się około 0,4s. Na co założyć index aby było szybsze?
Explain: