Anda harus menyingkirkan GROUP BY
di sini.
MySQL
kurang baik dalam mengoptimalkannya.
Tulis ulang kueri Anda seperti ini:
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
…
Buat indeks:
product_table__category_*__mm (uid_local, uid_foreign)
atau, lebih baik, nyatakan PRIMARY KEYs
di product_table__category_*__mm
:
ALTER TABLE product_table__category_*__mm ADD CONSTRAINT pk_pc*mm_local_foreign (uid_local, uid_foreign)