оптимизировать?
select count(distinct goods_category.id_item)
from goods_category
where goods_category.id_category = 225 and goods_category.id_item in (
select item1 from (select distinct id_item as item1 from goods_category where id_category in (225,230)) as t1
INNER JOIN (select distinct id_item as item2 from goods_category where id_category in (215)) as t2 on t1.item1=t2.item2
INNER JOIN (select distinct id_item as item3 from goods_category where id_category in (240,238,239,242,244,245,246)) as t3 on t2.item2=t3.item3
INNER JOIN (select distinct id_item as item4 from goods_category where id_category in (248,250)) as t4 on t3.item3=t4.item4
INNER JOIN (select distinct id_item as item5 from goods_category where id_category in (235,237)) as t5 on t4.item4=t5.item5
INNER JOIN (select distinct id_item as item6 from goods_category where id_category in (228,219,220,221,222,229)) as t6 on t5.item5=t6.item6
INNER JOIN (select distinct id_item as item7 from goods_category where id_category in (218)) as t7 on t6.item6=t7.item7
INNER JOIN (select distinct id_item as item8 from goods_category where id_category in (251,253,254,255,256,257,258,264)) as t8 on t7.item7=t8.item8
INNER JOIN (select distinct id_item as item9 from goods_category where id_category in (265,266)) as t9 on t8.item8=t9.item9
) and goods_category.id_item in (select distinct goods_category.id_item from goods_category where goods_category.id_category=96);
Тут 10 тысяч вложенных селектов. Их нельзя заменить парой инер джоинов?
Тут запрос строится на пересечении всех категорий, он в принципе мало оптимизируемый. Я подозреваю, что этих категорий ещё и переменное число, и запрос так вот как гармошка :[||||||||||||||||||||||||||||||||||||||||]:
Обсуждают сегодня