Tienes que deshacerte de GROUP BY
aquí.
MySQL
no es bueno para optimizarlo.
Vuelva a escribir su consulta así:
SELECT *
FROM product_table
WHERE EXISTS
(
SELECT NULL
FROM product_table__category_1__mm mm_1
JOIN category cat_1
ON cat_1.uid = mm_1.uid_foreign
WHERE mm_1.uid_local = product_table.uid
AND mm_1.uid_foreign IN (7, 8)
)
AND
…
Crea los índices:
product_table__category_*__mm (uid_local, uid_foreign)
o, mejor, declararlas PRIMARY KEYs
en product_table__category_*__mm
:
ALTER TABLE product_table__category_*__mm ADD CONSTRAINT pk_pc*mm_local_foreign (uid_local, uid_foreign)