Devi sbarazzarti di GROUP BY
qui.
MySQL
non va bene ottimizzarlo.
Riscrivi la tua domanda in questo modo:
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 gli indici:
product_table__category_*__mm (uid_local, uid_foreign)
o, meglio, dichiararle PRIMARY KEYs
su product_table__category_*__mm
:
ALTER TABLE product_table__category_*__mm ADD CONSTRAINT pk_pc*mm_local_foreign (uid_local, uid_foreign)