I have the following tables:
products - 4500 records
Fields: id, sku, name, alias, price, special_price, quantity, desc, photo, manufacturer_id, model_id, hits, publication
products_attribute_rel - 35,000 entries
Fields: id, product_id, attribute_id, attribute_val_id
attribute_values - 243 entries
Fields: id, attr_id, value, order
manufacturers - 29 entries
Fields: id, title, publication
models - 946 entries
Fields: id, manufacturer_id, name, publication
So, I get data from these tables for one query:
SELECT jp.*, jm.id AS jm_id, jm.title AS jm_title, jmo.id AS jmo_id, jmo.title AS jmo_title FROM `products` AS jp LEFT JOIN `products_attribute_rel` AS jpar ON jpar.product_id = jp.id LEFT JOIN `attribute_values` AS jav ON jav.attr_id = jpar.attribute_val_id LEFT JOIN `manufacturers` AS jm ON jm.id = jp.manufacturer_id LEFT JOIN `models` AS jmo ON jmo.id = jp.model_id GROUP BY jp.id HAVING COUNT(DISTINCT jpar.attribute_val_id) >= 0
This request is slow as hell. Processing takes a few seconds of mysql. So how can this query be improved? With small pieces of data, it works perfectly. But I think all the ruins of the products_attribute_rel table, which has 35,000 entries.
Your help will be greatly appreciated.
EDITED
EXPLAIN SELECT query results:
