Здравствуйте! Есть такой запрос
select distinct `pfv`.`value_id`
from `products`
left join `product_filter_value` as `pfv` on `pfv`.`product_id` = `products`.`id`
where `products`.`category_id` = '12'
and exists (select * from `filter_values` inner join `product_filter_value` on `filter_values`.`id` = `product_filter_value`.`value_id` where `products`.`id` = `product_filter_value`.`product_id` and `filter_values`.`id` in ('4', '5', '6'))
and exists (select * from `filter_values` inner join `product_filter_value` on `filter_values`.`id` = `product_filter_value`.`value_id` where `products`.`id` = `product_filter_value`.`product_id` and `filter_values`.`id` in ('8', '9', '12', '14', '15', '16'))
and exists (select * from `filter_values` inner join `product_filter_value` on `filter_values`.`id` = `product_filter_value`.`value_id` where `products`.`id` = `product_filter_value`.`product_id` and `filter_values`.`id` in ('1', '2', '3', '800', '802', '803', '804'))
Можете дать совет как его оптимизировать? Проовал через join но скорость падала